From 5ad241dc14d13d1bc760710129968590fac64d07 Mon Sep 17 00:00:00 2001 From: Xargana Date: Tue, 25 Mar 2025 12:00:04 +0300 Subject: [PATCH] Initial commit v2 --- status/index.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 status/index.js diff --git a/status/index.js b/status/index.js new file mode 100644 index 0000000..70fb650 --- /dev/null +++ b/status/index.js @@ -0,0 +1,40 @@ +const express = require("express"); +const axios = require("axios"); + +const app = express(); +const PORT = 2589; // Change this if needed + +const CHECK_INTERVAL = 30 * 1000; // 30 seconds +const REMOTE_SERVER = "http://example.com"; // Change this to your target server + +let serverStatus = { + online: false, + lastChecked: null, + responseTime: null, + }; + + // Function to check server status + async function checkServer() { + const startTime = Date.now(); + try { + await axios.get(REMOTE_SERVER, { timeout: 5000 }); // 5-second timeout + serverStatus.online = true; + } catch (error) { + serverStatus.online = false; + } + serverStatus.responseTime = Date.now() - startTime; + serverStatus.lastChecked = new Date().toISOString(); + } + + // Check the server at intervals + setInterval(checkServer, CHECK_INTERVAL); + checkServer(); // Initial check + + // API route to get the status + app.get("/status", (req, res) => { + res.json(serverStatus); + }); + + app.listen(PORT, () => { + console.log(`Server running on http://localhost:${PORT}`); + });