aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-11 04:58:29 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-11 04:58:29 -0700
commit3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6 (patch)
tree923d54a2bf187b1827865ad26c59fadd6b5f019d /examples
parentac3835227eb66ea340122db614e6f32fa17a5697 (diff)
downloadbun-3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6.tar.gz
bun-3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6.tar.zst
bun-3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6.zip
[bun.js] Add a `Server.stop` function
Diffstat (limited to 'examples')
-rw-r--r--examples/http-stop.ts12
-rw-r--r--examples/http.ts1
2 files changed, 12 insertions, 1 deletions
diff --git a/examples/http-stop.ts b/examples/http-stop.ts
new file mode 100644
index 000000000..64d3abfa1
--- /dev/null
+++ b/examples/http-stop.ts
@@ -0,0 +1,12 @@
+const server = Bun.serve({
+ fetch(req: Request) {
+ return new Response(`Pending requests: ${this?.pendingRequests ?? 0}`);
+ },
+});
+
+setTimeout(() => {
+ // stop the server after the first request
+ // when the server is stopped, this becomes undefined
+ server?.stop();
+ console.log("Stopping the server...");
+}, 1000);
diff --git a/examples/http.ts b/examples/http.ts
index 97caf6bfc..8b17c320c 100644
--- a/examples/http.ts
+++ b/examples/http.ts
@@ -21,7 +21,6 @@ Bun.serve({
port: 3000, // number or string
});
-
// Start a fast HTTP server from the main file's export
// export default {
// fetch(req) {