Still missing CORS header
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.
-
Try add a slash to the end of the request -
http://pokeapi.co/api/v2/ -
Try change API endpoints from http://pokeapi.co/api/v2 to http://pokeapi.salestock.net/api/v2 It works! ๐ ๐ ๐
-
Or as a temporary remedy, you can try cors.now.sh https://cors.now.sh/https://pokeapi.co/api/v2/
The app seems to work, on my side.
I don't know why, but now it seems worked ๐
still don't work ๐ญ

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

I have the same problem, can't seem to find a fix to it
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
Calling API through HTTPS solved the issue for me, although I don't really understand how.
@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
I'm getting a 504 error instead when using https

I still get this exact problem. Switched to https and still na da. Any fix?
Https request also requires Cloudflare verification which is not usable on client-side API calls.
So Cloudflare messes up the request. If anybody could investigate...
Yeah, cloudflare messes up the request. Change API endpoints from http://pokeapi.co/api/v2 to http://pokeapi.salestock.net/api/v2 It works! ๐ ๐ ๐
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?
As a temporary remedy, you can try cors.now.sh
https://cors.now.sh/https://pokeapi.co/api/v2/pokemon/1/
call via https is worked for me
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 You could try digging on why Cloudflare sometimes strips away CORS headers
@phalt, is cloudflare configured properly?
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 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