This commit is contained in:
Xargana 2025-03-26 17:59:23 +03:00 committed by GitHub
parent 49ec7aa4ab
commit 4ed640f497
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,19 +6,19 @@ const app = express();
const PORT = 2589; // Set the API to run on port 2589 const PORT = 2589; // Set the API to run on port 2589
const CHECK_INTERVAL = 30 * 1000; // Check every 30 seconds const CHECK_INTERVAL = 30 * 1000; // Check every 30 seconds
const REMOTE_SERVER = "https://example.com"; // Change this to the server you want to check const REMOTE_SERVER = "https://srv.xargana.com"; // Change this to the server you want to check
let serverStatus = { let serverStatus = {
online: false, online: false,
lastChecked: null, lastChecked: null,
responseTime: null, responseTime: null,
}; };
// Enable CORS to allow requests from other domains // Enable CORS to allow requests from other domains
app.use(cors()); app.use(cors());
// Function to check server status // Function to check server status
async function checkServer() { async function checkServer() {
const startTime = Date.now(); const startTime = Date.now();
try { try {
await axios.get(REMOTE_SERVER, { timeout: 5000 }); // 5-second timeout await axios.get(REMOTE_SERVER, { timeout: 5000 }); // 5-second timeout
@ -28,19 +28,18 @@ let serverStatus = {
} }
serverStatus.responseTime = Date.now() - startTime; serverStatus.responseTime = Date.now() - startTime;
serverStatus.lastChecked = new Date().toISOString(); serverStatus.lastChecked = new Date().toISOString();
} }
// Run the check every 30 seconds // Run the check every 30 seconds
setInterval(checkServer, CHECK_INTERVAL); setInterval(checkServer, CHECK_INTERVAL);
checkServer(); // Initial check checkServer(); // Initial check
// API route to get the server status // API route to get the server status
app.get("/status", (req, res) => { app.get("/status", (req, res) => {
res.json(serverStatus); res.json(serverStatus);
}); });
// Start the server on port 2589
app.listen(PORT, () => {
console.log(`API running at https://blahaj.tr:${PORT}`);
});
// Start the server on port 2589
app.listen(PORT, () => {
console.log(`API running at https://localhost:${PORT}`);
});