Skip to content

vite-plugin websocket proxy doesn't work when using an address other than localhost #10045

@russelldavis

Description

@russelldavis

What versions & operating system are you using?

Wrangler 4.25.0, Vite 7.0.5, macOS 15.5

Please provide a link to a minimal reproduction

https://github.com/russelldavis/workers-chat-demo/tree/vite

Describe the Bug

The repro is based on https://github.com/cloudflare/workers-chat-demo, just modified to use vite and vite-plugin.

If you run it locally (using vite dev) and open it in your browser at http://localhost:5173/ it works fine. But if you open it at the local IP address instead (which vite show as something like Network: http://192.168.0.105:5173/ when it runs, enabled by setting server: {host: true} in the vite config), the websocket connection will fail.

This bug makes it impossible to test websockets locally with vite dev on multiple devices (because the actual ip address, not localhost is needed on devices other than where the server is running).

This bug is really hard to investigate, because wrangler/miniflare/vite-plugin don't log anything when the websocket connection is rejected. And Chrome doesn't even show the status code when that happens.

After adding some logging of my own, I tracked it down to a 401 error that gets returned here. Miniflare is rejecting anything that doesn't have a Host header of 127.0.0.1, [::1], or localhost.

I think the fix is to set the Host header to "localhost" in vite-plugin here. I tested that locally and it fixes the issue.

Please provide any relevant error logs

No response

Metadata

Metadata

Assignees

Labels

bugSomething that isn't workingvite-pluginRelating to the `@cloudflare/vite-plugin` package

Type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions