|
const http = require('http'); |
|
const { exec } = require('child_process'); |
|
const PORT = 7860; |
|
const RESTART_INTERVAL_MS = 5 * 60 * 60 * 1000; |
|
|
|
const startServer = () => { |
|
const server = http.createServer((req, res) => { |
|
res.writeHead(200, { 'Content-Type': 'text/html' }); |
|
res.end('<html><body><b><marquee>KING Alya<marquee></b></body></html>'); |
|
}); |
|
|
|
server.listen(PORT, () => { |
|
console.log(`Server listening on port ${PORT}`); |
|
}); |
|
|
|
return server; |
|
}; |
|
|
|
let server = startServer(); |
|
|
|
|
|
const restartServer = () => { |
|
console.log('Restarting server...'); |
|
|
|
server.close(() => { |
|
console.log('Server stopped.'); |
|
server = startServer(); |
|
}); |
|
}; |
|
|
|
|
|
setInterval(restartServer, RESTART_INTERVAL_MS); |
|
|
|
|
|
process.on('uncaughtException', (err) => { |
|
console.error('Uncaught Exception:', err); |
|
restartServer(); |
|
}); |
|
|
|
process.on('unhandledRejection', (reason, promise) => { |
|
console.error('Unhandled Rejection at:', promise, 'reason:', reason); |
|
restartServer(); |
|
}); |