From 34b46f6346c1f649aa45c2571274a66fa06a88c9 Mon Sep 17 00:00:00 2001 From: TotallyNotElite Date: Tue, 12 Jan 2021 21:39:51 +0100 Subject: [PATCH] [FIX] Prevent reverse proxy 5xx codes from triggering a page reload Prior to this fix, the MeshCentral page would automatically reload itself after 10 seconds even if MeshCentral is still down when behind a reverse proxy like NGINX. --- views/default-mobile.handlebars | 4 +++- views/default.handlebars | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/views/default-mobile.handlebars b/views/default-mobile.handlebars index 73092916..4d4efae6 100644 --- a/views/default-mobile.handlebars +++ b/views/default-mobile.handlebars @@ -1076,7 +1076,9 @@ if (!xdr) xdr = new XMLHttpRequest(); xdr.open('HEAD', window.location.href); xdr.timeout = 15000; - xdr.onload = function () { reload(); }; + // Make sure there isn't a reverse proxy in front that may just be returning 5xx codes + // Status code 4xx should still be allowed, since a page could potentially be removed, etc + xdr.onload = function () { if (xdr.status < 500) reload(); else setTimeout(serverPoll, 10000); }; xdr.onerror = xdr.ontimeout = function () { setTimeout(serverPoll, 10000); }; xdr.send(); } diff --git a/views/default.handlebars b/views/default.handlebars index 92163348..90e5eb35 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1849,7 +1849,9 @@ if (!xdr) xdr = new XMLHttpRequest(); xdr.open('HEAD', window.location.href); xdr.timeout = 15000; - xdr.onload = function () { reload(); }; + // Make sure there isn't a reverse proxy in front that may just be returning 5xx codes + // Status code 4xx should still be allowed, since a page could potentially be removed, etc + xdr.onload = function () { if (xdr.status < 500) reload(); else setTimeout(serverPoll, 10000); }; xdr.onerror = xdr.ontimeout = function () { setTimeout(serverPoll, 10000); }; xdr.send(); }