0
router.get("/", (req, res) => {
  res.setHeader("Access-Control-Allow-Origin", "http://localhost:3000");
  User.find()
    .sort({ name: -1 })
    .then(theUsers => {
      res.json(theUsers);
    });
});

I have put the header. It also shows in postman. Why does it keep blocking me?

enter image description here

I have also put * on the value but still does not work.

1 Answers1

-1

why not use cors in your server.js file set it before the line where your routes are.

npm install cors

const cors = require("cors")

app.use(cors())

then your route here

app.use("/api",routes)