I have a project that is only a frontend, built with React, in which I am trying to make a call to an external API when an LI is clicked. Here is my code for one of my components. I took out the actual url from this snippet because it is very long, but the call works when using Postman.
Your problem is that you are loading your app using
file://, the browser will not use the
CORS policies with
You must use a local server like
Nginx to serve your frontend app and load again with
localhost, in that case, the request to the API will have the header
Origin with value and the server will accept it.
If you are developing frontend apps, it's not a good way to load with
file://, use always a local web server.