Tuesday, 19 May 2020

[Newbie - Express] CORS middleware library does not work for POST requests?

I have a site where when I click the button, I call app.post("/") is triggered.​Here's my express:const express = require("express"); const app = express(); const port = process.env.PORT || 5000; var cors = require("cors"); app.use(cors()); app.options("*", cors()); // console.log that your server is up and running app.listen(port, () => console.log(`Listening on port ${port}`)); app.post("/", cors(), (req, res) => { res.send({ express: "post json object" }); }); my error: origin 'http://localhost:3000' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response. ​Did I set it up wrong?​

Submitted May 20, 2020 at 06:14AM by badboyzpwns

No comments:

Post a Comment