-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshutdown-server.js
More file actions
33 lines (30 loc) · 1.05 KB
/
shutdown-server.js
File metadata and controls
33 lines (30 loc) · 1.05 KB
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
import http from 'http';
import { exec } from 'child_process';
const server = http.createServer((req, res) => {
if (req.url === '/api/shutdown' && (req.method === 'POST' || req.method === 'GET')) {
console.log('[Shutdown Server] Shutdown requested');
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: 'Shutting down dev server...' }), () => {
// Wait for response to be sent, then gracefully exit
setTimeout(() => {
console.log('[Shutdown Server] Exiting gracefully...');
// Send SIGTERM to parent process (concurrently will handle it)
process.emit('SIGTERM');
process.exit(0);
}, 500);
});
} else {
res.writeHead(404);
res.end();
}
});
// Handle shutdown signals
process.on('SIGTERM', () => {
console.log('[Shutdown Server] Received SIGTERM');
server.close(() => {
process.exit(0);
});
});
server.listen(5174, 'localhost', () => {
console.log('[Shutdown Server] Running on http://localhost:5174');
});