From 33bd349e430e91441fc2d3a51eaeb0ae0010041e Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 28 Nov 2022 20:10:44 -0800 Subject: [PATCH] Add fallback to HTTP GET for ping --- src/pages/api/ping.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pages/api/ping.js b/src/pages/api/ping.js index 79c7da0c..09934f06 100644 --- a/src/pages/api/ping.js +++ b/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" }); - 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({ status,