-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebSocket proxy in middleware mode #4124
Comments
If you approve this proposal, I would like to work on this and create a PR. |
I just stumbled across this, while writing a vite plugin. httpServer is not exposed so there is no way to listen for |
I think we could add a vite/packages/vite/src/node/server/hmr.ts Line 26 in 9e06b81
|
Is this the only hinderance? Socket.io supports setting upgrade false and transport to WebSockets only. if the WebSockets proxy is doing it's job in vite, our WS server should respond throught the proxy, even if our WS server is only listening for vite's proxy server traffic. I'm going to try to make a sandbox with a websockets proxy setup today. I'm looking to try vite-node if I find vite disagreeable. |
News on this? I have to proxy websockets and I cannot make them work with vite anyway |
Two years and no fix on that ? This is a critical feature. |
Clear and concise description of the problem
vite's WebSocket proxy doesn't work in middleware mode even if set
ws: true
like the following.Because
httpServer
is required to set up WebSocket proxy buthttpServer
becomesnull
in middleware mode.vite/packages/vite/src/node/server/index.ts
Lines 315 to 317 in 5c177db
vite/packages/vite/src/node/server/index.ts
Line 462 in 5c177db
vite/packages/vite/src/node/server/middlewares/proxy.ts
Lines 60 to 73 in 5c177db
So, we have to add WebSocket proxy code in our code with a way like copy&paste from
proxyMiddleware
inproxy.ts
. This is a little inconvenient.Suggested solution
I think it would be very useful to be able to pass the parent server like
hmr
.The following link shows an example implementation.
tomoam@38e54e7
In this case, WebSocket proxy will work in middleware mode, without adding any complicated code.
Alternative
export
proxyMiddleware
.The following link shows an example implementation.
tomoam@328610d
In this case, we will need to find and update the configured proxy middleware, but we will not need to copy and paste the code from
proxy.ts
and importhttp-proxy
, and the impact will be minimal for vite.Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: