diff --git a/README.md b/README.md index 4aca57e..20b649a 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ Detect if running in a test environment to disable some features. - Default: `true` -Automatically close when an exit signal is received in the process. +Automatically close when an `exit` event, `SIGTERM`, `SIGINT` or `SIGHUP` signal is received in the process. ### `publicURL` diff --git a/src/listen.ts b/src/listen.ts index 7e5e0e9..a71f201 100644 --- a/src/listen.ts +++ b/src/listen.ts @@ -276,7 +276,11 @@ export async function listen( } if (listhenOptions.autoClose) { - process.on("exit", () => close()); + process.setMaxListeners(0); + process.once("exit", () => close()); + process.once("SIGINT", () => process.exit(0)); // Ctrl + C + process.once("SIGTERM", () => process.exit(0)); // Terminate + process.once("SIGHUP", () => process.exit(0)); // Closed terminal } return {