I am using react to send data to my API. Every POST request I make gives me an OPTIONS request, and I need to fix this. I think I might need to do some preflight structure but a
app.post
is as the name implies, for POST
requests. OPTIONS
request won't get routed to that method.
You need to write a handler specific for options like so,
app.options("*",function(req,res,next){
res.header("Access-Control-Allow-Origin", req.get("Origin")||"*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
//other headers here
res.status(200).end();
});