[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.

TotallyNotElite committed Jan 12, 2021 at 21:39 UTC 34b46f6346c1f649aa45c2571274a66fa06a88c9
2 files changed +6 -2
views/default-mobile.handlebars
+3 -1
@@ -1076,7 +1076,9 @@
1076 if (!xdr) xdr = new XMLHttpRequest();
1077 xdr.open('HEAD', window.location.href);
1078 xdr.timeout = 15000;
1079 - xdr.onload = function () { reload(); };
1079 + // Make sure there isn't a reverse proxy in front that may just be returning 5xx codes
1080 + // Status code 4xx should still be allowed, since a page could potentially be removed, etc
1081 + xdr.onload = function () { if (xdr.status < 500) reload(); else setTimeout(serverPoll, 10000); };
1082 xdr.onerror = xdr.ontimeout = function () { setTimeout(serverPoll, 10000); };
1083 xdr.send();
1084 }
views/default.handlebars
+3 -1
@@ -1849,7 +1849,9 @@
1849 if (!xdr) xdr = new XMLHttpRequest();
1850 xdr.open('HEAD', window.location.href);
1851 xdr.timeout = 15000;
1852 - xdr.onload = function () { reload(); };
1852 + // Make sure there isn't a reverse proxy in front that may just be returning 5xx codes
1853 + // Status code 4xx should still be allowed, since a page could potentially be removed, etc
1854 + xdr.onload = function () { if (xdr.status < 500) reload(); else setTimeout(serverPoll, 10000); };
1855 xdr.onerror = xdr.ontimeout = function () { setTimeout(serverPoll, 10000); };
1856 xdr.send();
1857 }