From 49ec7aa4abc6dbe7407ea4d3f247433540b193b7 Mon Sep 17 00:00:00 2001 From: Xargana Date: Tue, 25 Mar 2025 12:33:35 +0300 Subject: [PATCH] a --- status/{index.js => server.js} | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) rename status/{index.js => server.js} (71%) diff --git a/status/index.js b/status/server.js similarity index 71% rename from status/index.js rename to status/server.js index 70fb650..f93245f 100644 --- a/status/index.js +++ b/status/server.js @@ -1,11 +1,12 @@ const express = require("express"); const axios = require("axios"); +const cors = require("cors"); const app = express(); -const PORT = 2589; // Change this if needed +const PORT = 2589; // Set the API to run on port 2589 -const CHECK_INTERVAL = 30 * 1000; // 30 seconds -const REMOTE_SERVER = "http://example.com"; // Change this to your target server +const CHECK_INTERVAL = 30 * 1000; // Check every 30 seconds +const REMOTE_SERVER = "https://example.com"; // Change this to the server you want to check let serverStatus = { online: false, @@ -13,6 +14,9 @@ let serverStatus = { responseTime: null, }; + // Enable CORS to allow requests from other domains + app.use(cors()); + // Function to check server status async function checkServer() { const startTime = Date.now(); @@ -26,15 +30,17 @@ let serverStatus = { serverStatus.lastChecked = new Date().toISOString(); } - // Check the server at intervals + // Run the check every 30 seconds setInterval(checkServer, CHECK_INTERVAL); checkServer(); // Initial check - // API route to get the status + // API route to get the server status app.get("/status", (req, res) => { res.json(serverStatus); }); + // Start the server on port 2589 app.listen(PORT, () => { - console.log(`Server running on http://localhost:${PORT}`); + console.log(`API running at https://blahaj.tr:${PORT}`); }); + \ No newline at end of file