mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-09 06:48:47 +00:00
parent
2ab05350a3
commit
1c456b70c0
6 changed files with 123 additions and 18 deletions
28
src/pages/api/ping.js
Normal file
28
src/pages/api/ping.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { performance } from "perf_hooks";
|
||||
|
||||
import createLogger from "utils/logger";
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
|
||||
const logger = createLogger("ping");
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { ping: pingURL } = req.query;
|
||||
|
||||
if (!pingURL) {
|
||||
logger.debug("No ping URL specified");
|
||||
return res.status(400).send({
|
||||
error: "No ping URL given",
|
||||
});
|
||||
}
|
||||
|
||||
const startTime = performance.now();
|
||||
const [status] = await httpProxy(pingURL, {
|
||||
method: "HEAD"
|
||||
});
|
||||
const endTime = performance.now();
|
||||
|
||||
return res.status(200).json({
|
||||
status,
|
||||
latency: endTime - startTime
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue