fix: lack of SIGTERM handling.
This commit is contained in:
+12
-4
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user