cross-origin request blocked the same origin policy disallows reading the remote resource fix in node js node js code example

Example: cross-origin request blocked the same origin policy disallows reading the remote resource fix in node js node js

app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});

Tags:

Misc Example