0
votes

I keep getting this in my console and i don't understand, please can somebody help me and explain. Access to fetch at 'https://randomuser.me/api/?results=4' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

2
What request are you making? A simple GET shouldn't need any CORS handling. Give a minimal reproducible example. fetch('https://randomuser.me/api/?results=4').then((res) => res.json()).then((body) => console.log(body)) works as expected in my browser.jonrsharpe

2 Answers

0
votes

In your api domain https://randomuser.me, add localhost to your list of allowed origin.

The reason you're getting this error is because https://randomuser.me expects request from origin https://randomuser.me and not from some other sources like from your localhost. If this is not satisfied it will be returned as a warning/error by your browser.

-1
votes

To be able to allow API Proxy within a react app - You need to edit the package.json with the following

"proxy": "https://randomuser.me",

More details can be found on the create-react-dev docs