How to allow multiple domains for CORS in a simplified form.
I have
cors: {
origin: "www.one.com";
}
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", cors.origin);
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
This works when there is only one domain mentioned in origin
But if I want to have originas an array of domains, and I want to enable CORS for all domains in the source array, I would have something like this -
cors: {
origin: ["www.one.com","www.two.com","www.three.com"];
}
But then the problem is that the code below does not work -
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", cors.origin);
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
How to make res.headertake an array of domains through cors.origin?
source
share