mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
docs(server): fix satisfies Serve type in export default example (#25410)
This commit is contained in:
@@ -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.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
Reference in New Issue
Block a user