diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/http-stop.ts | 12 | ||||
-rw-r--r-- | examples/http.ts | 1 |
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) { |