fix: lack of SIGTERM handling.

This commit is contained in:
2026-05-09 20:05:34 +02:00
parent 286fcdbe5b
commit 2699efc773
4 changed files with 33 additions and 17 deletions
+12 -4
View File
@@ -205,7 +205,7 @@ function getClientIp(req) {
function parseArgs(argv) {
let bind = "0.0.0.0";
let port = 8000;
let port = 8080;
let look = "nice";
for (let i = 0; i < argv.length; i += 1) {
@@ -253,7 +253,7 @@ function parseArgs(argv) {
"",
"Defaults:",
" --bind 0.0.0.0",
" --port 8000",
" --port 8080",
" --look nice",
].join("\n");
console.log(help);
@@ -267,6 +267,7 @@ function parseArgs(argv) {
}
function run(bind, port, look) {
let isShuttingDown = false;
const server = http.createServer((req, res) => {
const method = req.method || "GET";
@@ -309,10 +310,17 @@ function run(bind, port, look) {
console.log(`Serving on ${bind}:${port} (default look=${look}) (Ctrl-C to stop)`);
});
process.on("SIGINT", () => {
function handleShutdownSignal() {
if (isShuttingDown) {
return;
}
isShuttingDown = true;
console.log("\nShutting down server");
server.close(() => process.exit(0));
});
}
process.on("SIGINT", handleShutdownSignal);
process.on("SIGTERM", handleShutdownSignal);
}
try {