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

hmm Still no solution for this I see...

I tried everything mentioned on this post and nothing worked

Ma7eer avatar Jul 21 '18 15:07 Ma7eer

Having this issue on Firefox Quantum 61.0.1, NOT having this issue on Google Chrome 67.0.3 using https://pokeapi.co/api/v2/

Weird thing is that if I make the request from Firefox's console, it works, but not when requesting from my Javascript file.

Neodecadente avatar Jul 29 '18 18:07 Neodecadente

Was stuck on this for a while @Bingbazaar! Thanks! Sorry this hasn't been fixed for other people, hope it gets resolved soon.

Jace-Beaudoin avatar Aug 02 '18 17:08 Jace-Beaudoin

CORS seems to be strange overall - I can get this endpoint to work fine in Firefox and Chrome: https://pokeapi.co/api/v2/pokemon/1/

But not this one, which should be equivalent to that: https://pokeapi.co/api/v2/pokemon/bulbasaur/

Just adding some info to the pile.

bclindner avatar Sep 22 '18 20:09 bclindner

@bclindner This is a side effect of the outage we had Thursday and Friday. We implemented a quick fix (uploading static JSON files to the server) in anticipation of moving the API to a static host at some point in the near future, but not everything works. Named endpoints only work for pokemon right now, for example. There are still a couple of hurdles to get over, but once we finally move to static hosting on Netlify, all of these issues should be solved.

See #369 for details of the outage, and #350 for the whole story.

cmmartti avatar Sep 22 '18 20:09 cmmartti

@naramsim Do you want to check if the CORS header fix applies to the named resource symlinks as well?

tdmalone avatar Sep 22 '18 21:09 tdmalone

I added the CORS to named res. https://pokeapi.co/api/v2/pokemon/golduck/

Naramsim avatar Sep 22 '18 21:09 Naramsim

Any suggestions for those running a site with HTTPS that doesn't allow for HTTP calls? I tried using the salestock.net domain for the call and it worked great on my local environment, but my live site is using HTTPS and is blocking the request. There doesn't seem to be a working HTTPS version of pokeapi.salestock.net.

I started using the alternate domain when using the regular pokeapi.co was being blocked. For some reason, even though I am making the call directly to HTTPS://pokeapi.co/api/v2/pokemon/1, I keep getting a CORS error where it seems like its still calling directly to HTTP.

Example: https://vibrant-yonath-715bf2.netlify.com/

SilasOtoko avatar Oct 20 '18 05:10 SilasOtoko

@SilasOtoko Try adding a trailing slash. For some reason, I was getting a CORS error without one. Currently, PokéAPI is hosted on a Digital Ocean server, but we will shortly move to completely static hosting on Firebase, which should fix this.

If adding a trailing slash doesn't work, try using https://pokeapi-215911.firebaseapp.com/api/v2/ instead. That's the temporary Firebase app URL for PokéAPI that we will be moving to at some point. I'm curious to know whether that solves your problem or not.

cmmartti avatar Oct 20 '18 05:10 cmmartti

The Firebase URL worked perfectly, and it seems much faster too! Thanks! :)

SilasOtoko avatar Oct 20 '18 06:10 SilasOtoko

Good to hear. Just be sure to switch back to pokeapi.co once the move to Firebase Hosting is complete.

cmmartti avatar Oct 20 '18 06:10 cmmartti

Good to know. Thanks :)

SilasOtoko avatar Oct 20 '18 06:10 SilasOtoko

Hi I'm creating an angularjs client application that consumes this api just for didactics purposes.

I getting the same error.

this is what i'm doing:

var getPokemons = function(){
   return $http({
     method: 'GET',
     url: 'https://pokeapi.co/api/v2/pokemon/'
   });
}

gerabu avatar Nov 16 '18 18:11 gerabu

Do you get these headers in the response? If you try from your browser? Or maybe using curl or wget

access-control-allow-headers: Authorization, Origin, X-Requested-With, Content-Type, Accept
access-control-allow-methods: GET, OPTIONS
access-control-allow-origin: *

Naramsim avatar Nov 16 '18 19:11 Naramsim

I get these headers only when i make the request from postman i can't make it works in angularjs

gerabu avatar Nov 18 '18 01:11 gerabu

@GeraldAburto I've never used Angular and don't know how the $http function works. Is there any way to set the mode to cors like in the fetch API?

cmmartti avatar Nov 18 '18 01:11 cmmartti

You could also consider to use our browser wrapper. https://github.com/PokeAPI/pokeapi-js-wrapper

Naramsim avatar Nov 18 '18 17:11 Naramsim

My purpose is to teach how to use angularjs to consume a web API

gerabu avatar Nov 19 '18 14:11 gerabu

Always use HTTPS to avoid CORS issues.

Naramsim avatar Jan 22 '19 08:01 Naramsim