cwise89 / react-detect-offline

Offline and Online components for React
MIT License
1.29k stars 99 forks source link

Polling issue with URL: CORS #74

Closed AymenMarouani closed 3 years ago

AymenMarouani commented 3 years ago

Hi,

Thanks a lot for the library, it saved my day,

Actually I'm using the Detector component in polling mode to detect if the user went offline or lost the network connection, I provided a URL for ping, but the problem was that I receive a CORS error that pollutes the browser's console, is it possible to just ignore the CORS error and consider a simple ping ? after all, if I received an answer and my browsers sees a CORS, I'm online.

I did the following wrokaround, <Detector polling={{url:`${window.location.origin}/ui`}}/>

Best Regards.

aehmt commented 3 years ago

Having similar issue, using Offline component. https://api.ipify.org/?format=json request is throwing CORS error with HTTP 405 Method Not Allowed in some parts of the Europe and India.

Serginh0 commented 3 years ago

Hello, I'm also using the Detector component, the new ping url (https://api.ipify.org/?format=json ) is also giving CORS error, I'm from South America (Brazil), did you manage to solve this problem?

cwise89 commented 3 years ago

looking into another solution for default polling url.

lenni-io commented 3 years ago

Same issue.

cwise89 commented 3 years ago

The fix has been released. It is now pointing at the Star Wars API URL. After this learning experience we all faced with this issue, let's keep reminded that we cannot rely on external services and I highly recommend not relying on the default polling url- use it as a fallback.

Thank you all for your understanding! :)

Closing.

beevelop commented 3 years ago

Quick heads up @cwise89: You might have quite some difficulties using the Star Wars API. It's quite easy to get a Maximum requests reached. Try again later. response.

So, I'd recommend considering, making the request URL a required configuration, instead of switching the "unintentional DDOS targets" regularly. 😉