aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-02-27 21:24:59 -0300
committerGravatar GitHub <noreply@github.com> 2023-02-27 16:24:59 -0800
commit4b627457540c7c6ef79e7133672e282bb0e61702 (patch)
treeeb7e95f56b9d2b655db6b227ccb7a085cfa4d47a /src
parent0afb1693d370c0dd1340b3eb7659d31ef3fc94a3 (diff)
downloadbun-4b627457540c7c6ef79e7133672e282bb0e61702.tar.gz
bun-4b627457540c7c6ef79e7133672e282bb0e61702.tar.zst
bun-4b627457540c7c6ef79e7133672e282bb0e61702.zip
add signal on http.Server.listen (#2223)
* add signal on http.Server.listen * actual call close instead of just stopping the server
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/http.exports.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/bun.js/http.exports.js b/src/bun.js/http.exports.js
index 59e2d3483..61bb77e04 100644
--- a/src/bun.js/http.exports.js
+++ b/src/bun.js/http.exports.js
@@ -207,6 +207,7 @@ export class Server extends EventEmitter {
}
this.#options = options;
+
if (callback) this.on("request", callback);
}
@@ -232,8 +233,13 @@ export class Server extends EventEmitter {
if (typeof port === "function") {
onListen = port;
} else if (typeof port === "object") {
+ port?.signal?.addEventListener("abort", ()=> {
+ this.close();
+ });
+
host = port?.host;
port = port?.port;
+
if (typeof port?.callback === "function") onListen = port?.callback;
}
const ResponseClass = this.#options.ServerResponse || ServerResponse;