Browse Source

Merge pull request #587 from benphelps/ping-fallback

Change: Add fallback to http GET for ping
shamoon 2 years ago
parent
commit
b0cce6dbde
1 changed files with 10 additions and 3 deletions
  1. 10 3
      src/pages/api/ping.js

+ 10 - 3
src/pages/api/ping.js

@@ -15,11 +15,18 @@ export default async function handler(req, res) {
         });
         });
     }
     }
     
     
-    const startTime = performance.now();
-    const [status] = await httpProxy(pingURL, {
+    let startTime = performance.now();
+    let [status] = await httpProxy(pingURL, {
       method: "HEAD"
       method: "HEAD"
     });
     });
-    const endTime = performance.now();
+    let endTime = performance.now();
+    
+    if (status >= 400 && status < 500) {
+      // try one more time as a GET in case HEAD is rejected for whatever reason
+      startTime = performance.now();
+      [status] = await httpProxy(pingURL);
+      endTime = performance.now();
+    }
 
 
     return res.status(200).json({
     return res.status(200).json({
       status,
       status,