react.js | how to get rid of cross-origin error in Codesandbox react.js | how to get rid of cross-origin error in Codesandbox reactjs reactjs

react.js | how to get rid of cross-origin error in Codesandbox


It looks like you need to enable CORS on your S3 bucket that serves: https://s3-eu-west-1.amazonaws.com/codesandbox-downtime/downtime.json

To do so, just navigate to your bucket, then click the Permissions tab, then in the CORS box enter an XML document with the permissions you'd like. Sample permissions to allow any host to make a GET request:

<?xml version="1.0" encoding="UTF-8"?><CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><CORSRule>    <AllowedOrigin>http://*</AllowedOrigin>    <AllowedOrigin>https://*</AllowedOrigin>    <AllowedMethod>GET</AllowedMethod></CORSRule><CORSRule>    <AllowedOrigin>*</AllowedOrigin>    <AllowedMethod>GET</AllowedMethod></CORSRule></CORSConfiguration>


I have my server setup to support CORS and it's still giving me this error.

It looks like an issue with ReactJS if there is an error while processing a response from the server. In my case it was happening while trying to parse invalid response into JSON.


You can use corsproxy to hit localhost API's from your local machines.

  1. You first need to install the corsproxy npm package.npm install -g corsproxy

  2. run corsproxy command on terminal

  3. It will run on http://localhost:1337
  4. Now what you need to do is append your api call with the above url. Lets say you need to hit localhost:3000/customer to hit api.

So new url will be http://localhost:1337/localhost:3000/customer

This will remove CORS error.

Do comments your queries in comments.