Search code examples
timeoutcloudflare

Cloudflare 524 error with AJAX


I'm making an ajax request to a site behind Cloudflare. After 100 seconds, I get a 524. However I'm unable to process that 524 in my Javascript as the error page is served directly by Cloudflare and does not contain the required Access-Control-Allow-Origin headers.

I wish to retry the query in the event of getting a 524.


Solution

  • If you know that CloudFlare edge will wait for a HTTP response from the server for exactly 100 seconds, then you could just setup a timeout equal to 100 seconds on the ajax request. And retry the query after the timeout.

    Alternatively, you can move this request into subdomain which is not under cloud flare proxy.


    Another idea is to use a reverse proxy and adding CORS headers. In the Apache that would be

    <LocationMatch "/ajax-request-used-in-js">
       ProxyPass http://example.com/ajax
       Header add "Access-Control-Allow-Origin" "*"
    </LocationMatch>