0

Hi I get a :

127.0.0.1/:1 Access to XMLHttpRequest at ‘http://localhost:4000/api/products’ from origin ‘http://127.0.0.1:5173’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
HomePage.tsx:54 GET http://localhost:4000/api/products net::ERR_FAILED

Despite having:

app.use(
  cors({
    credentials: true,
    origin: [“http://localhost:5173”%5D,
  })
);
, cors , and @types/cors installed

I even have :

axios.defaults.baseURL =
  process.env.NODE_ENV === “development” ? “http://localhost:4000” : “/”; in my frontend  main.tsx . There is no difference between my and the instructor’s code and yet I can’t get around this error. Anyone have an idea?

Irina Posted new comment June 1, 2023

solved: just change origin: [‘http://localhost:5173’] to origin: [“http://127.0.0.1:5173”],