Enable cross origin ( CORS ) in NodeJs

app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header("Access-Control-Allow-Headers", "X-Requested-With,X-Powered-By,Content-Type");
if (req.method === 'OPTIONS') {
res.status(200).end();
} else {
next();
}
});

No comments:

Post a Comment