The Traveling Coder
The Traveling Coder

Reputation: 311

CORS issue React Axios

I am trying to get a login screen to work on React, still new to this stuff. I have finally gotten requests to at least partially work, but now I am getting this error

Access to XMLHttpRequest at 'http://localhost:5000/login' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource

I read a few articles and came across this one https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9

Which says to use this code

Access-Control-Allow-Origin: http://localhost:3000

But I am not sure exactly where this line of code should go.

Upvotes: 0

Views: 333

Answers (1)

Nathan Sainsbury
Nathan Sainsbury

Reputation: 443

I believe this needs to be fixed on the API. I'm not sure what you're hosting on your API on, but if it's express, then doing something like:

const cors = require('cors');

app.use(cors());

Alternatively, for testing purposes, you can install cors plugins on chrome and firefox.

Upvotes: 3

Related Questions