How to enable DELETE request?
I solved it without adding new packages, just added this line
res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE");
Notice that i have my allowed methods separated by commas inside one string.The complete function looks like this:
app.use(function (req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"); next();});
Solved it by simply using npm's cors package and enabling all cors requests, by simply replacing...
// enable CORSapp.use(function (req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Methods", "GET", "PUT", "POST", "DELETE", "OPTIONS"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"); next();});
with...
app.use(require('cors')());
But I'm still not sure what magic cors package is doing under the hood to make it work.