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