pokeapi icon indicating copy to clipboard operation
pokeapi copied to clipboard

Still missing CORS header

Open dwicao opened this issue 9 years ago โ€ข 39 comments

Hi! I've used PokeAPI in my React.js pure client-side app [repo], any API calls fail because it still missing CORS header, although I've been set a user agent header { 'User-Agent': 'cheese' }, any workarounds?

SOLVED: cloudflare messes up the request.

  1. Try add a slash to the end of the request - http://pokeapi.co/api/v2/

  2. Try change API endpoints from http://pokeapi.co/api/v2 to http://pokeapi.salestock.net/api/v2 It works! ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰

  3. Or as a temporary remedy, you can try cors.now.sh https://cors.now.sh/https://pokeapi.co/api/v2/

dwicao avatar May 26 '17 02:05 dwicao

The app seems to work, on my side.

Naramsim avatar May 27 '17 12:05 Naramsim

I don't know why, but now it seems worked ๐ŸŽ‰

dwicao avatar Jun 11 '17 05:06 dwicao

still don't work ๐Ÿ˜ญ image

dwicao avatar Sep 21 '17 02:09 dwicao

My app also stopped working few days ago due to similar error. cors

antilama avatar Sep 28 '17 20:09 antilama

I have the same problem, can't seem to find a fix to it

Mjain10 avatar Sep 29 '17 04:09 Mjain10

Probably is something related to our CDN provider, CloudFlare.

Try to make direct HTTPS calls

Also, try to remove any User Agent Header you have

Naramsim avatar Sep 29 '17 12:09 Naramsim

Calling API through HTTPS solved the issue for me, although I don't really understand how.

antilama avatar Sep 29 '17 15:09 antilama

@antilama Probably our Cloudflare when redirecting http to https (somebody probably enabled HSTS) strips away our 'Access-Control-Allow-Origin' header.

If this solution work for @Mjain10 we can close

Naramsim avatar Sep 29 '17 15:09 Naramsim

I'm getting a 504 error instead when using https issue

Mjain10 avatar Sep 30 '17 01:09 Mjain10

I still get this exact problem. Switched to https and still na da. Any fix?

arfianadam avatar Sep 30 '17 07:09 arfianadam

Https request also requires Cloudflare verification which is not usable on client-side API calls.

arfianadam avatar Sep 30 '17 07:09 arfianadam

So Cloudflare messes up the request. If anybody could investigate...

Naramsim avatar Sep 30 '17 11:09 Naramsim

Yeah, cloudflare messes up the request. Change API endpoints from http://pokeapi.co/api/v2 to http://pokeapi.salestock.net/api/v2 It works! ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰

dwicao avatar Oct 03 '17 23:10 dwicao

Even with http://pokeapi.salestock.net/api/v2, it works for sometime and later it stops working with the same CORS as the issue. What can be done?

krinsane avatar Oct 10 '17 08:10 krinsane

As a temporary remedy, you can try cors.now.sh

https://cors.now.sh/https://pokeapi.co/api/v2/pokemon/1/

Naramsim avatar Oct 10 '17 09:10 Naramsim

call via https is worked for me

davidnguyen11 avatar Nov 25 '17 08:11 davidnguyen11

I have the same problem. I created simple app in June and it was working fine with simple $.getJSON request, and now I came back to this app and it just stopped working. Is there any permanent idea how to solve this? HTTPS works with Chrome but error is still on Safari, no clue how with Firefox.

Koleja avatar Nov 29 '17 18:11 Koleja

@Koleja You could try digging on why Cloudflare sometimes strips away CORS headers

@phalt, is cloudflare configured properly?

Naramsim avatar Nov 29 '17 19:11 Naramsim

Oddly enough, it worked for me to just request data with the added / at the end. So like:

https://pokeapi.co/api/v2/pokemon/722/ instead of https://pokeapi.co/api/v2/pokemon/722

I don't know if it's gonna fix it for anybody else, but I thought I might as well post it here :)

Bingbazaar avatar Mar 25 '18 15:03 Bingbazaar

@Bingbazaar when putting a slash at the end you are avoiding a 301 redirect. Because pokeapi.co/api/v2/pokemon/722 redirects to pokeapi.co/api/v2/pokemon/722/. That means you gain also in performance

Naramsim avatar Mar 28 '18 12:03 Naramsim