Skip to content

Commit a1d530d

Browse files
committed
update docs to reflect the fact that websockets do not work with vite dev server
1 parent d738f22 commit a1d530d

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

docs/latest/advanced/websockets.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ description: |
66
Fresh provides built-in helpers for upgrading HTTP connections to WebSockets.
77
There are two main approaches depending on your use case.
88

9+
> [warn]: WebSocket upgrades do not work under the Vite dev server (`deno task
10+
> dev`). Both `app.ws()` and `ctx.upgrade()` rely on `Deno.upgradeWebSocket()`,
11+
> which requires Deno's native HTTP server to be handling the request. Vite
12+
> serves requests through a Node HTTP server and forwards them to Fresh as
13+
> synthesized `Request` objects, so the 101 upgrade response cannot be
14+
> completed and the `open` handler is never invoked.
15+
>
16+
> To test WebSocket endpoints locally, run a production-style build:
17+
>
18+
> ```sh
19+
> deno task build && deno task start
20+
> ```
21+
>
22+
> This runs `deno serve` directly, so `Deno.upgradeWebSocket()` works as
23+
> expected. If you need WebSockets during iterative development, run a
24+
> separate Deno entry point (e.g. `deno serve -A main.ts`) alongside Vite, or
25+
> host the WebSocket server as a sidecar on its own port.
26+
927
## Quick start with `app.ws()`
1028
1129
The simplest way to add a WebSocket endpoint:

0 commit comments

Comments
 (0)