docs(server): fix satisfies Serve type in export default example (#25410)

This commit is contained in:
robobun
2025-12-08 09:25:00 -08:00
committed by GitHub
parent 3af0d23d53
commit 4980736786

View File

@@ -193,15 +193,17 @@ This is the maximum amount of time a connection is allowed to be idle before the
Thus far, the examples on this page have used the explicit `Bun.serve` API. Bun also supports an alternate syntax. Thus far, the examples on this page have used the explicit `Bun.serve` API. Bun also supports an alternate syntax.
```ts server.ts ```ts server.ts
import { type Serve } from "bun"; import type { Serve } from "bun";
export default { export default {
fetch(req) { fetch(req) {
return new Response("Bun!"); return new Response("Bun!");
}, },
} satisfies Serve; } satisfies Serve.Options<undefined>;
``` ```
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.
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. 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.
--- ---