0

I'm trying to create requests on my api using firebase hosting the server is running on http://localhost:5000 and my client is running on http://localhost:3000 which creates this error

origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check

this is my backend code:

app.use(
  cors({
    origin: "http://localhost:3000",
    credential: true,
  })
);
app.use(function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "http://localhost:3000");
  res.header("Access-Control-Allow-Credentials", true);
  res.header(
    "Access-Control-Allow-Headers",
    "Origin, X-Requested-With, Content-Type, Accept, Authorization"
  );
  res.header("Access-Control-Allow-Methods: POST, GET, DELETE, PUT");
  next();
});

how should I set mt header for it to work

Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734
  • I found the solution to my problem here https://stackoverflow.com/questions/24897801/enable-access-control-allow-origin-for-multiple-domains-in-node-js – Nasereddin Kailani May 29 '22 at 17:11

0 Answers0