Cors issue with axios request to backend

ethancs13TRIAL

8 months 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

8 months 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.


ethancs13TRIAL

8 months ago

how do i fix this?


8 months ago

Point the domain to the correct port.


ethancs13TRIAL

8 months ago

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


8 months ago

Right here


ethancs13TRIAL

8 months 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


8 months ago

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


ethancs13TRIAL

8 months ago

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


8 months ago

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


ethancs13TRIAL

8 months ago

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

ethancs13TRIAL

8 months ago

is this not what is needed?

8 months ago

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


Cors issue with axios request to backend - Railway Help Station