Cors issue with axios request to backend

ethancs13
TRIAL

a year ago

My current application using React, MySQL and express is failing to get past the CORS error. I have setup the CORS in my server.js using...

But it seems like that method doesnt seem to be working. Github: https://github.com/ethancs13/dbdbdb

app.use(
  cors({
    origin: [process.env.CLIENT_ORIGIN],
    methods: ["POST", "GET", "DELETE"],
    credentials: true,
  })
);

12 Replies

a year ago

Cors is not the issue here.

Open your backend's domain in your browser and you will see that the application didn't respond.

Your domain is pointing to the wrong port.


ethancs13
TRIAL

a year ago

how do i fix this?


a year ago

Point the domain to the correct port.


ethancs13
TRIAL

a year ago

where would I do this? In the frontend react or backend express server? what would I set the variables to?


a year ago

Right here


ethancs13
TRIAL

a year ago

ive tried changing it to both 3000 and 3001, the two ports I am using, and both result in the same error on the frontend, with the backend working fine


a year ago

The server service uses the correct port now, but the frontend does not, please correct that as well.


ethancs13
TRIAL

a year ago

The front and backend seem to be working, but again there seems to be a CORS issue?


10 months ago

Yep, you would need to properly implement some CORS middleware.


ethancs13
TRIAL

10 months ago

app.use(
  cors({
    origin: [process.env.CLIENT_ORIGIN],
    methods: ["POST", "GET", "DELETE"],
    credentials: true,
  })
);

ethancs13
TRIAL

10 months ago

is this not what is needed?

10 months ago

I'm sorry but we are unable to provide coding help here.