Update: Npm Cors Doc
This commit is contained in:
parent
c6e02cf797
commit
f69ed4b3d4
2 changed files with 21 additions and 30 deletions
|
|
@ -1,28 +1,19 @@
|
|||
const cors = require('cors');
|
||||
module.exports.cors = cors;
|
||||
|
||||
const allowList = [
|
||||
const whitelist = [
|
||||
'http://127.0.0.1:4200',
|
||||
'http://127.0.0.1:4201',
|
||||
'https://admin-polynotfound.herokuapp.com',
|
||||
'https://polynotfound.herokuapp.com'
|
||||
];
|
||||
|
||||
const corsOptionsDelegate = function(req, callback) {
|
||||
console.log(req.header('Origin'), allowList.indexOf(req.header('Origin')));
|
||||
let corsOptions;
|
||||
if (allowList.indexOf(req.header('Origin')) !== -1) {
|
||||
corsOptions = {
|
||||
origin: true,
|
||||
credentials: true
|
||||
}
|
||||
} else {
|
||||
corsOptions = {
|
||||
origin: false,
|
||||
credentials: true
|
||||
module.exports.corsOptions = {
|
||||
origin: function(origin, callback) {
|
||||
if (whitelist.indexOf(origin) !== -1) {
|
||||
callback(null, true);
|
||||
} else {
|
||||
callback(new Error('Not allowed by CORS'));
|
||||
}
|
||||
}
|
||||
console.log(corsOptions);
|
||||
callback(null, corsOptions)
|
||||
}
|
||||
module.exports.options = corsOptionsDelegate;
|
||||
}
|
||||
Reference in a new issue