docs: serveBun — WebSocket on Bun
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
2 files changed
+28
-4
No files matched your search
@@ -12,6 +12,7 @@ green-tea uses calendar versioning: `YY.MM.PATCH`.
|
|||||||
same app runs HTTP and SSE on Deno/Bun/edge runtimes via the Fetch API
|
same app runs HTTP and SSE on Deno/Bun/edge runtimes via the Fetch API
|
||||||
(WebSocket and mesh remain Node-only).
|
(WebSocket and mesh remain Node-only).
|
||||||
- **Deno adapter** (`@green-tea/core/deno`): `serveDeno(app)` runs HTTP + SSE + WebSocket on Deno.
|
- **Deno adapter** (`@green-tea/core/deno`): `serveDeno(app)` runs HTTP + SSE + WebSocket on Deno.
|
||||||
|
- **Bun adapter** (`@green-tea/core/bun`): `serveBun(app)` runs HTTP + SSE + WebSocket on Bun, reusing the neutral `app.upgrade` / `WsSocket` capability. WebSocket, rooms, and channels behave identically to Node and Deno.
|
||||||
- **`app.upgrade(request, socket)`**: neutral WebSocket entry point for non-Node runtimes, built on a shared `WsSocket` capability. WebSocket logic is now runtime-agnostic (`src/http/ws-core.ts`).
|
- **`app.upgrade(request, socket)`**: neutral WebSocket entry point for non-Node runtimes, built on a shared `WsSocket` capability. WebSocket logic is now runtime-agnostic (`src/http/ws-core.ts`).
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ export default { fetch: app.fetch };
|
|||||||
**Node is the reference implementation** — every runtime returns the same status, headers,
|
**Node is the reference implementation** — every runtime returns the same status, headers,
|
||||||
and body for the same request (enforced by a parity test suite).
|
and body for the same request (enforced by a parity test suite).
|
||||||
|
|
||||||
**Not yet on Bun/edge runtimes:** WebSocket (`@Ws`) and mesh — still Node-only there; Deno now
|
**Not yet on edge runtimes:** WebSocket (`@Ws`) and mesh — still Node-only there; Deno and Bun
|
||||||
has WebSocket support via `serveDeno` (see below). `app.listen()` and TLS remain Node-only; on
|
now have full WebSocket support via `serveDeno` and `serveBun` (see below). `app.listen()` and
|
||||||
Deno/Bun/edge you get `app.fetch`.
|
TLS remain Node-only; on Deno/Bun/edge you get `app.fetch`.
|
||||||
|
|
||||||
**Body-size enforcement differs slightly:** on `app.fetch`, an oversized body is read in full
|
**Body-size enforcement differs slightly:** on `app.fetch`, an oversized body is read in full
|
||||||
before the `413` is returned, whereas Node aborts mid-stream once the limit is hit — so on
|
before the `413` is returned, whereas Node aborts mid-stream once the limit is hit — so on
|
||||||
@@ -54,7 +54,30 @@ run on Node. Behaviour matches the Node reference.
|
|||||||
|
|
||||||
**Advanced:** `app.upgrade(request, socket)` is the neutral primitive `serveDeno` uses.
|
**Advanced:** `app.upgrade(request, socket)` is the neutral primitive `serveDeno` uses.
|
||||||
Any runtime can build a `WsSocket` capability (`inbound`, `abort`, `isOpen`, `send`,
|
Any runtime can build a `WsSocket` capability (`inbound`, `abort`, `isOpen`, `send`,
|
||||||
`close`, `terminate`) and drive the graph — this is how Bun and edge support will land.
|
`close`, `terminate`) and drive the graph — `serveBun` builds on the same primitive
|
||||||
|
(see below), and this is how future edge support will land.
|
||||||
|
|
||||||
**Still Node-only:** `app.listen()`, TLS, per-request timeouts, and mesh. On Deno you
|
**Still Node-only:** `app.listen()`, TLS, per-request timeouts, and mesh. On Deno you
|
||||||
get `app.fetch` + `serveDeno`.
|
get `app.fetch` + `serveDeno`.
|
||||||
|
|
||||||
|
## WebSocket on Bun
|
||||||
|
|
||||||
|
`app.fetch` covers HTTP + SSE on every runtime. WebSocket needs a runtime-specific
|
||||||
|
upgrade, so Bun gets a dedicated adapter at `@green-tea/core/bun`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { createApp } from '@green-tea/core';
|
||||||
|
import { serveBun } from '@green-tea/core/bun';
|
||||||
|
|
||||||
|
const app = createApp({ modules: [ChatModule] });
|
||||||
|
|
||||||
|
// HTTP + SSE via app.fetch, WebSocket via Bun's server-level handler — one call:
|
||||||
|
serveBun(app, { port: 8000 });
|
||||||
|
```
|
||||||
|
|
||||||
|
`serveBun` routes normal requests through `app.fetch` and WebSocket upgrades through
|
||||||
|
`app.upgrade` — the same graph, the same `@Ws` handlers, the same rooms/channels you
|
||||||
|
run on Node and Deno. Behaviour matches the Node reference.
|
||||||
|
|
||||||
|
**Still Node-only:** `app.listen()`, TLS, per-request timeouts, and mesh. On Bun you
|
||||||
|
get `app.fetch` + `serveBun`.
|
||||||
Reference in new issue
Block a user