1

I am trying to access an API with my react application. Specifically, I am trying to access the IGDB API. Since I am getting CORS errors, I am trying to set up a proxy as mentioned on their website: https://api-docs.igdb.com/#cors-for-js-ionic

I am unable to set up this proxy to get bypass this. Would something like AnyProxy work?

Lewis Menelaws
  • 1,186
  • 5
  • 20
  • 42
  • Are you trying to access an external api on a dev environment? If you are, you can add a proxy field to your package.json and that'll avoid CORS issues. More info found here - https://facebook.github.io/create-react-app/docs/proxying-api-requests-in-development – Shawn Yap Apr 17 '19 at 19:35
  • What domain would I put under this proxy parameter? I am trying to access https://api-v3.igdb.com/games – Lewis Menelaws Apr 17 '19 at 19:38

2 Answers2

3

Expanding on my comment on proxy here for better view.

Here's an example of how that might look like.

package.json

{
 "proxy": "http://api-v3.igdb.com"
}

fetch.js

function fetchGames() {
 fetch('/games')
}
Shawn Yap
  • 969
  • 7
  • 12
0

This question drove me crazy. I decided to CORS Anywhere. Essentially, you use it as a gateway between your development environment and the public API you are trying to consume. For me doing this: https://cors-anywhere.herokuapp.com/https://api-v3.igdb.com/games/?search=Halo

was the solution to my error.

Lewis Menelaws
  • 1,186
  • 5
  • 20
  • 42