ajnisbet/opentopodata

API blocking fetch requests

Closed this issue · 1 comments

I'm trying to implement the API by fetching the JSON via JavaScript's fetch API or jQuery, but I'm getting an error that access to fetch the API has been "blocked by CORS policy," which usually indicates that the end site is blocking fetch requests.
Screenshot 2020-08-09 at 3 47 27 PM

Am I doing something wrong or is this as intended?

Hey, thanks for raising this!

The open software in this repo has full support for browser-based fetch requests and CORS policy. However, the free instance I'm hosting at api.opentopodata.org is configured to block cross-origin requests. These requests effectively bypass the per-IP rate limit, and I want to make sure the server has enough capacity for everyone!

So there are a couple of options to get this working:

  • Host ajnisbet/opentopodata on your own server with CORS enabled
  • Proxy requests from api.opentopodata.org through your own server, adding the appropriate CORS header
  • If you're working on academic research or a small non-commercial project, send me an email and I can add you to a whitelist on the public api.
  • Use the GPXZ elevation api