-2

I've made a React app with CoinGeko API.

But if I refresh more than 3 time, the app start loading forever.

I have this message on my console, I can't solve it:

Access to fetch at 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=&order=market_cap_desc&per_page=10&page=3&sparkline=false&price_change_percentage=1h%2C24h%2C7d' 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. CryptoContext.js:38

GET https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=&order=market_cap_desc&per_page=10&page=3&sparkline=false&price_change_percentage=1h%2C24h%2C7d net::ERR_FAILED 429

You can find the Git repository here : repo

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
imnotremi
  • 19
  • 7
  • Usually this means that front end applications can't reach the 3rd party API. What you can do, is pass your fetch request to a node proxy server, which makes the call for you. These APIs don't like to be touched by UI code typically – Sterling Archer Mar 23 '23 at 17:22
  • Does this answer your question? [No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API](https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe) – David Mar 23 '23 at 17:23
  • Or this: https://stackoverflow.com/q/25845203/328193 Or this: https://stackoverflow.com/q/25310450/328193 Or this: https://stackoverflow.com/q/10636611/328193 There are ***many*** duplicates that you can find by searching for the error message you're seeing. – David Mar 23 '23 at 17:24

1 Answers1

1

You have an error code 429, which is means "too many requests": https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429

(this can appear as a CORS error if the server doesn't set application headers on 4xx or 5xx errors)

The rate limit for coingecko is 10 - 30 requests per minute: https://www.coingecko.com/en/api/pricing

Daniel Jamrozik
  • 1,228
  • 2
  • 11
  • 25
  • *"this can appear as a CORS error if the server doesn't set application headers on 4xx or 5xx errors"* - Interesting, I hadn't encountered that before. If that's the case then the OP should definitely file that as a bug with the service if CORS should otherwise be allowed. – David Mar 23 '23 at 17:28