|
|
@ -3,7 +3,6 @@ import { performance } from "perf_hooks";
|
|
|
|
import { getServiceItem } from "utils/config/service-helpers";
|
|
|
|
import { getServiceItem } from "utils/config/service-helpers";
|
|
|
|
import createLogger from "utils/logger";
|
|
|
|
import createLogger from "utils/logger";
|
|
|
|
import { httpProxy } from "utils/proxy/http";
|
|
|
|
import { httpProxy } from "utils/proxy/http";
|
|
|
|
import {importCookieHeader} from "utils/proxy/cookie-jar";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const logger = createLogger("ping");
|
|
|
|
const logger = createLogger("ping");
|
|
|
|
|
|
|
|
|
|
|
@ -26,24 +25,20 @@ export default async function handler(req, res) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (req.headers.cookie) {
|
|
|
|
|
|
|
|
importCookieHeader(pingURL, req.headers.cookie)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
let startTime = performance.now();
|
|
|
|
let startTime = performance.now();
|
|
|
|
let [status] = await httpProxy(pingURL, {
|
|
|
|
let [status] = await httpProxy(pingURL, {
|
|
|
|
method: "HEAD"
|
|
|
|
method: "HEAD"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
let endTime = performance.now();
|
|
|
|
let endTime = performance.now();
|
|
|
|
|
|
|
|
|
|
|
|
if (status > 403) {
|
|
|
|
if (status > 403) {
|
|
|
|
// try one more time as a GET in case HEAD is rejected for whatever reason
|
|
|
|
// try one more time as a GET in case HEAD is rejected for whatever reason
|
|
|
|
startTime = performance.now();
|
|
|
|
startTime = performance.now();
|
|
|
|
[status] = await httpProxy(pingURL);
|
|
|
|
[status] = await httpProxy(pingURL);
|
|
|
|
endTime = performance.now();
|
|
|
|
endTime = performance.now();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
return res.status(200).json({
|
|
|
|
status,
|
|
|
|
status,
|
|
|
|
latency: endTime - startTime
|
|
|
|
latency: endTime - startTime
|
|
|
|