Skip to content
Advertisement

In React Js Axios request getting CROS error

I used Axios for API, here is my code. I am getting CROS error.

axios({
      method: 'GET',
      headers : { 'Content-Type': 'application/json',
                  'Access-Control-Allow-Origin' : '*',
                  'mode': 'cors',
                  'Authorization':'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1N....'
                },
      url: baseURL,          
    }).then(function (response) {
          console.log(response);
    });

enter image description here

Advertisement

Answer

You’ll need to enable CORS from your back-end service. From the image, it is clear that your front-end in running on localhost on port 3000 whereas your back-end or api service is running on port 8000 on localhost. So, enable CORS from your back-end or api serivce.

Advertisement