You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/runtime/http/server.mdx
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -193,15 +193,17 @@ This is the maximum amount of time a connection is allowed to be idle before the
193
193
Thus far, the examples on this page have used the explicit `Bun.serve` API. Bun also supports an alternate syntax.
194
194
195
195
```ts server.ts
196
-
import{ typeServe } from"bun";
196
+
importtype {Serve } from"bun";
197
197
198
198
exportdefault {
199
199
fetch(req) {
200
200
returnnewResponse("Bun!");
201
201
},
202
-
} satisfiesServe;
202
+
} satisfiesServe.Options<undefined>;
203
203
```
204
204
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
+
205
207
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.
0 commit comments