Update: Move Cors inside Routes definition

This commit is contained in:
Yûki VACHOT 2021-12-23 13:18:04 +01:00
parent a12926f277
commit f26fcdc961
3 changed files with 39 additions and 23 deletions

26
config/cors.config.js Normal file
View file

@ -0,0 +1,26 @@
const cors = require('cors');
module.exports.cors = cors;
const allowList = [
'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) {
let corsOptions;
if (allowList.indexOf(req.header('Origin')) !== -1) {
corsOptions = {
origin: true,
credentials: true
}
} else {
corsOptions = {
origin: false,
credentials: true
}
}
callback(null, corsOptions)
}
module.exports.options = corsOptionsDelegate;