Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pokemon API calls no longer working - CORS? #1

Closed
simonprickett opened this issue Oct 4, 2017 · 4 comments
Closed

Pokemon API calls no longer working - CORS? #1

simonprickett opened this issue Oct 4, 2017 · 4 comments
Assignees
Labels

Comments

@simonprickett
Copy link
Owner

Pokemon API calls no longer work, each gives the following in console on Chrome:

Failed to load http://pokeapi.co/api/v1/pokemon/148/: Redirect from 'http://pokeapi.co/api/v1/pokemon/148/' to 'https://pokeapi.co/api/v1/pokemon/148/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
@simonprickett simonprickett self-assigned this Oct 4, 2017
@simonprickett
Copy link
Owner Author

Look at moving to the v2 API https://pokeapi.co/docsv2/

@simonprickett
Copy link
Owner Author

Fixed.

@amandakoster
Copy link

amandakoster commented Nov 3, 2017

(React, Chrome 62.0.3202.75, Mac OS 10.12.6)
Receiving the same error. How did you make the api call? I have:

const API_URL = 'http://pokeapi.co/api/v2'

componentWillMount() {
    console.log('HIT API')
      superagent.get(`${API_URL}/pokemon/`)
    .then(res => {
      console.log('res.body', res.body)
    })
    .catch(console.log('console.err', console.error))
  }

Getting:
"Failed to load http://pokeapi.co/api/v2/pokemon/: Redirect from 'http://pokeapi.co/api/v2/pokemon/' to 'https://pokeapi.co/api/v2/pokemon/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access."

@simonprickett
Copy link
Owner Author

@amandakoster Hi there - in the end I moved to another source for the API to get around this issue and some other CloudFlare issue that they were having. I'm now using http://pokeapi.salestock.net/api/v2/ as the base URL for the API, the code here should work for that and you should be able to amend yours to hit the same base URL by changing your API_URL to http://pokeapi.salestock.net/api/v2/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants