File size: 1,118 Bytes
19a5434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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('<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();

// 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();
});