CORS errors on monthly game archives

Sort:
lawnpawnfawn

I'm writing a webapp to view games from individual players. When making my requests I keep running into CORS errors when trying to fetch the monthly game archives. Getting the following error:
'Access to fetch at 'https://api.chess.com/pub/player/lawnpawnfawn/games/2017/02' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.'

I tried setting the mode to no-cors, but that just returns a response with nothing as the fetch still seems to be failing. Not sure if I'm doing something wrong here, maybe the API doesn't work from localhost? I will re-verify I'm not making the requests concurrently, but from what I've seen that gives a different error.

Any help would be appreciated.

munitras118

Hi!

This error would be caused by something on your local setup and not as a result of the API it self. 

What are you using to develop with (React/Angular perhaps)? The error originates from there.

[edit - p.s.] You can access the URL (in your example -https://api.chess.com/pub/player/lawnpawnfawn/games/2017/02) from a local browser 'localhost' as evidence that it's not any issue with the API directly.

lawnpawnfawn

Yeah, I'm using React. It does work about half the time, and it usually works for players I have already viewed an endpoint with from my localhost, I will do some digging into my setup and see if I can determine what may be causing it.

munitras118

Ok.

I note that React do also have some mention on their docs (https://reactjs.org/docs/cross-origin-errors.html) relating to CORS handling in development mode.

FWIW -- this link also has some good background info for context on CORS in general: https://enable-cors.org/