Skip to content

Commit 4980736

Browse files
authored
docs(server): fix satisfies Serve type in export default example (#25410)
1 parent 3af0d23 commit 4980736

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

docs/runtime/http/server.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,17 @@ This is the maximum amount of time a connection is allowed to be idle before the
193193
Thus far, the examples on this page have used the explicit `Bun.serve` API. Bun also supports an alternate syntax.
194194

195195
```ts server.ts
196-
import { type Serve } from "bun";
196+
import type { Serve } from "bun";
197197

198198
export default {
199199
fetch(req) {
200200
return new Response("Bun!");
201201
},
202-
} satisfies Serve;
202+
} satisfies Serve.Options<undefined>;
203203
```
204204

205+
The type parameter `<undefined>` represents WebSocket data — if you add a `websocket` handler with custom data attached via `server.upgrade(req, { data: ... })`, replace `undefined` with your data type.
206+
205207
Instead of passing the server options into `Bun.serve`, `export default` it. This file can be executed as-is; when Bun sees a file with a `default` export containing a `fetch` handler, it passes it into `Bun.serve` under the hood.
206208

207209
---

0 commit comments

Comments
 (0)