I have an app using the cors
npm package as middleware. I have it set up like this:
if(process.env.NODE_ENV === 'production') {
var whitelist = ['http://mywebsite.com', 'https://mywebsite.com']
var corsOptions = {
origin: (origin, callback) => {
var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
console.log('ORIGIN: ', origin); // => undefined
callback(originIsWhitelisted ? null : 'Bad Request', originIsWhitelisted)
},
credentials:true
}
app.use(cors(corsOptions));
}
The origin
parameter in my corsOptions is undefined
. Why is this and how can I fix it?