I am working on a MEAN-STACK application.Using Mean-cli packgae of node. in which i am using darksky weather API, in package name Information. I have 4 other packages in custom folder of mean app. how did i enable the CORS so that all API request did not fail and return the response.
i googled and find out that i have to add this middleware.
//CORS middleware
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', 'example.com');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
where should i add this. in each package where we are using cross-origin request or in some global file.
I have tried to add this middleware in server -route file of ? Information package and in express.js file of confile but it didn't work.
See Question&Answers more detail:os