cors-express2
v1.0.0
Published
Express middleware to enable cross origin resource sharing on a route
Downloads
3
Readme
CORS middleware
A simple Express middleware to enable cross origin resource sharing on a route. It will deals with access-control-allow-origin
, access-control-allow-credentials
, access-control-request-headers
and access-control-allow-methods
headers. OPTIONS
preflight requests will be directly answered with a HTTP 200 - OK
.
Usage
var Express = require('express');
var cors = require('cors');
var app = Express();
express.use(cors({
allowWithoutOrigin: true,
onlyAllowedOrigin: true,
allowCredentials: true,
allowedOrigins: [
'http://127.0.0.1:8181',
'http://localhost:8181'
],
nullOrigin: 'null'
}));
Options
allowWithoutOrigin
: iftrue
, allow requests without origin, settingaccess-control-allow-origin=*
onlyAllowedOrigin
: iftrue
, requires the origin to be in the list of allowed originsallowCredentials
: iftrue
, will setaccess-control-allow-credentials=true
allowedOrigins
: an array of string representing the allowed originsnullOrigin
: set the string corresponding tonull
origin, most likely the default will always be ok