Reputation: 39
I have a React app(CRA) which is hosted on Firebase and am trying to access an external Rest API(using javascript's fetch()
) , but as that API is not on the same domain as the web-app , it throws a "CORS" error. The API has the header Access-Control-Allow-Origin
as *
.
I can work this around using a proxy in package.json
in development mode , but nothing seems to work after the app is hosted.
Have tried the below things
Firebase.json
to include headersno-cors
mode while using fetch()
Upvotes: 0
Views: 667
Reputation: 26333
The proper CORS header is Access-Control-Allow-Origin
, not Access-Control-Origin
. Also, depending on the nature of the request you may need a preflight request and may not be able to use *
as the origin.
There is nothing you can do on the client side to bypass CORS -- it is expressly designed as a browser security mechanism to prevent unexpected cross-domain requests. If you have control of the API server, you should be able to fix this. If you don't, you may need to use a Cloud Function to proxy requests to the external API.
Upvotes: 2