const http = require('http'); const { exec } = require('child_process'); const PORT = 7860; const RESTART_INTERVAL_MS = 5 * 60 * 60 * 1000; // 5 hours in milliseconds const startServer = () => { const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end('
'); }); server.listen(PORT, () => { console.log(`Server listening on port ${PORT}`); }); return server; }; let server = startServer(); // Function to restart the server const restartServer = () => { console.log('Restarting server...'); server.close(() => { console.log('Server stopped.'); server = startServer(); }); }; // Set up the interval to restart the server every 5 hours setInterval(restartServer, RESTART_INTERVAL_MS); // Error handling process.on('uncaughtException', (err) => { console.error('Uncaught Exception:', err); restartServer(); }); process.on('unhandledRejection', (reason, promise) => { console.error('Unhandled Rejection at:', promise, 'reason:', reason); restartServer(); });