From 0547f58c654d3fa53fb608bcbf66aa158b667d7b Mon Sep 17 00:00:00 2001 From: Marco Gallegos Date: Tue, 25 Nov 2025 13:03:59 -0600 Subject: [PATCH] feat: add health check endpoint with VPS ping using `child_process.exec`. --- server.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/server.js b/server.js index 6bb857d..6f8d687 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,8 @@ const express = require("express"); const path = require("path"); +const { exec } = require("child_process"); + const app = express(); const port = process.env.PORT || 3000; const rootDir = path.join(__dirname); @@ -14,6 +16,26 @@ app.get("/healthchecker", (req, res) => { res.sendFile(path.join(rootDir, "scripts", "health_checker")); }); +// Standard health check endpoint for monitoring with VPS ping +app.get("/health", (req, res) => { + const vpsIp = "31.97.41.188"; + // Ping with count 1 and timeout 1 second + exec(`ping -c 1 -W 1 ${vpsIp}`, (error, stdout, stderr) => { + const isAlive = !error; + res.status(200).json({ + status: "ok", + timestamp: new Date().toISOString(), + checks: { + vps_ping: { + target: vpsIp, + alive: isAlive, + output: isAlive ? "VPS Reachable" : "VPS Unreachable", + }, + }, + }); + }); +}); + // Fallback to index.html for other routes (optional) app.get("*", (req, res) => { res.sendFile(path.join(rootDir, "index.html"));