1.0.0 • Published 6 years ago
cors-express2 v1.0.0
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=trueallowedOrigins: an array of string representing the allowed originsnullOrigin: set the string corresponding tonullorigin, most likely the default will always be ok
1.0.0
6 years ago