Open OlegWock opened 5 months ago
This is still an issue. Any server.proxy
configuration within Vite config does not work in bun. Currently have:
server: {
proxy: {
"/api": {
ws: true,
target: `http://localhost:${PORT}`,
},
},
},
Adding changeOrigin
or rewriteWsOrigin
doesnt help, nor does a complex configure()
method help since the response is already sent.
The problem is likely within node-http-proxy
but IMO this issue should exist here for bun's node compat.
This issue persists, preventing me from migrating to the Bun environment because I still need to use a dev proxy that enables WebSocket.
What version of Bun is running?
1.1.4+fbe2fe0c3
What platform is your computer?
Darwin 23.4.0 arm64 arm
What steps can reproduce the bug?
bunx --bun vite
websocat
):What is the expected behavior?
WebSocket proxy connection is established, you can send messages (enter text and press enter in websocat) and get response. This is how it works with node.
What do you see instead?
WebSocket between client and proxy is established, but connection between proxy and server fails.
Additional information
There seem to be some differencies how
http
works in Node and Bun. I was able to pinpoint the issue likely to these lines:https://github.com/http-party/node-http-proxy/blob/9b96cd725127a024dabebec6c7ea8c807272223d/lib/http-proxy/passes/ws-incoming.js#L112-L120
On Node:
response
doesn't seem to emitted at allupgrade
is emittedOn Bun:
response
event is emitted, butres.upgrade
is undefined, so connection between proxy and server is closedupgrade
not emittedPackage node-http-proxy isn't maintained, but used by Vite. Also,
res.upgrade
seem to be error as there is no such property on Node docs. But in the end it's difference in events order that breaks proxying