0👍
Try this instead of what you have now
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin,X-Requested-With,Content-Type,Accept,Authorization"
);
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow-Methods', 'PUT,POST,GET')
return res.status(200).json({});
}
next();
});
0👍
Install CORS
npm install cors
Now, include it into app()
var express = require('express')
var cors = require('cors')
var app = express()
app.use(cors())
Source:stackexchange.com