Nodejs CORS fixing it for ExpressJs



Getting CORS issue with chrome browser which requires CORS to be enable. Never ever listen to people who ask you to change your fetch API call to use 'mode' : 'cors' - You gonna get error - saying promise rejected.

This can be configure using code below :-




app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

app.get('/', function(req, res, next) {
  // Handle the get for this route
});

app.post('/', function(req, res, next) {
 // Handle the post for this route
});



Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm