I am having a weird issue. I get cors error for put request on browser:
Access to fetch at 'http://localhost:3015/pathtest/api/v1/results/cc7637578fad1a6fcfb4249fbf000a13/load' from origin 'https://localhost:9444' has been blocked by CORS policy: Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.
And here is my code to enable cors in backend(nodejs). All the other api requests have been fixed with the below code and only put still returns cors issue:
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");
// res.header('Access-Control-Allow-Methods', 'PATCH, PUT, POST, GET, DELETE, OPTIONS');
// // allow preflight
// if (req.method === 'OPTIONS') {
// res.send(200);
// } else {
// next();
// }
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
// allow preflight
if (req.method === 'OPTIONS') {
res.send(200);
} else {
next();
}
});
Am I missing anything?
**Update