Skip to content

Commit 8c2cfa5

Browse files
committed
docs: Add transport docs
1 parent e10b8f7 commit 8c2cfa5

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

docs/content/server/mounting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Mount Fetch Functions
33
description: Zeta is WinterCG compliant, meaning you can mount other standard server-side fetch functions on your app.
4-
weight: 6
4+
weight: 7
55
---
66

77
## Overview

docs/content/server/transports.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: Transports
3+
description: Transports provide access to runtime-specific APIs.
4+
weight: 6
5+
---
6+
7+
By default, Zeta uses `createFetchTransport`. It detects your runtime and provides a minimal transport that supports Bun and Deno.
8+
9+
## Runtime-specific Decorations
10+
11+
The default fetch transport not provide access to runtime-specific APIs. For example, in Bun, you use the `server` arg to setup websockets or get the request IP address:
12+
13+
```ts
14+
Bun.serve({
15+
fetch: (request, server) => {
16+
const ip = server.requestIP(request);
17+
// ...
18+
},
19+
});
20+
```
21+
22+
To access the same object, you need to provide a custom `transport` then transport-specific APIs will be available in the request context:
23+
24+
```ts
25+
import { createApp } from "@aklinker1/zeta";
26+
import { createBunTransport } from "@aklinker1/zeta/transports/bun-transport";
27+
28+
const app = createApp({
29+
transport: createBunTransport(),
30+
}).get(({ request, server }) => {
31+
const ip = server.requestIP(request);
32+
// ...
33+
});
34+
```
35+
36+
You only have to add the transport once, to your top-level app, and any runtime-specific decorations will be made available in all child-apps as well!
37+
38+
## Transport Options
39+
40+
Some transports also support passing custom options:
41+
42+
```ts
43+
import { createBunTransport } from "@aklinker1/zeta/transports/bun-transport";
44+
45+
const transport = createBunTransport({
46+
websocket: {
47+
// ...
48+
},
49+
});
50+
51+
const app = createApp({
52+
transport,
53+
});
54+
```

0 commit comments

Comments
 (0)