The CORS middleware for PXE.js.
Install @pxe/cors
.
# NPM
npm i @pxe/cors
# Yarn
yarn add @pxe/cors
All stuff to handle Cross-origin resource sharing.
CORS
options?: CORS.Options
: The optionsConstruct a CORS middleware.
cors.invoke
ctx: Server.Context
: The server contextnext: Server.NextFunction
: Call the next middleware...args: any[]
: The previous middleware passed argumentsThe callback of the middleware. This can be used as a middleware:
app.use(cors.invoke.bind(cors));
// Or shorter
app.use(cors);
All CORS middleware options.
options.allowOrigins
string | string[]
Allows the specified origins to make request to the server. By default all origins are allowed.
options.allowMethods
string | Server.RequestMethod[]
Allow clients to request to the server with specified request method. By default all methods are allowed.
options.exposeHeaders
string | string[]
Expose specified headers to the client. Cache-Control
, Content-Length
, Content-Language
, Content-Type
, Expires
, Last-Modified
, Pragma
are headers that is exposed by default.
options.maxAge
number
Maximum number of seconds the results can be cached, as an unsigned non-negative integer. The default value is 5
.
options.allowCredentials
boolean
Indicates whether or not the response to the request can be exposed when the credentials flag is true. When used as part of a response to a preflight request, this indicates whether or not the actual request can be made using credentials.
options.allowHeaders
string | string[]
Indicate which HTTP headers can be used when making the actual request. This field is optional.