has been blocked by cors policy node js server code example
Example 1: nodejs CORS policy
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "YOUR-DOMAIN.TLD");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.get('/', function(req, res, next) {
});
app.post('/', function(req, res, next) {
});
Example 2: Access to XMLHttpRequest has been blocked by CORS policy node js
const cors = require('cors');
const corsOptions ={
origin:'http://localhost:3000',
credentials:true,
optionSuccessStatus:200
}
app.use(cors(corsOptions));