Skip to content
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

Reuse Nuxt's WebSocket #112

Closed
antfu opened this issue Mar 7, 2023 · 4 comments · Fixed by #243
Closed

Reuse Nuxt's WebSocket #112

antfu opened this issue Mar 7, 2023 · 4 comments · Fixed by #243
Labels
discussion enhancement New feature or request

Comments

@antfu
Copy link
Member

antfu commented Mar 7, 2023

Currently, we are creating a new WS entry to do server-client communication:

server.middlewares.use(ROUTE_ENTRY, tinyws() as any)
server.middlewares.use(ROUTE_ENTRY, rpcMiddleware as any)

Since Nuxt DevTools is relying on Vite (I see in the near future, we probably only support Vite), I guess reusing Vite's WS would make things more efficient and stable. As Vite has the capability of handling custom events now: vitejs/vite#7437

This could potentially solve the connection issue in back-proxy or dockers, as Vite handles them well. Also could align with the approaches of vite-plugin-inspect etc.

/cc @pi0 you mentioned previously about reusing WS from Nitro, do you think it's still a thing, and what's your opinion on choosing which over which?

@antfu antfu added enhancement New feature or request discussion labels Mar 7, 2023
@pi0
Copy link
Member

pi0 commented Mar 7, 2023

I believe the second port (either the vite or custom port we are currently using for devtools) would share the same issues for remote sharing and docker as it needs extra configuration in the Nuxt setup.

Also even though vite is the default builder, design-wise Nuxt shouldn't depend its ecosystem and DX directly on a specific bundler (this way we can introduce new bundlers without huge migration costs like Nuxt 2 to Nuxt 3)

Working on a new nuxi dev server to implement a similar layer for shared WS listening on the same port of Nuxt and it keeps alive across Nuxt/Nitro/Builder restarts. Maybe it is something we could work on together.

@antfu antfu changed the title Reuse Vite WebSocket Reuse Nuxt's WebSocket Mar 7, 2023
@antfu
Copy link
Member Author

antfu commented Mar 7, 2023

That sounds great if Nuxt itself is going to have a WS server 👍. Changed the title

@bf
Copy link

bf commented Mar 7, 2023

I've spend considerable time figuring out websockets on nuxt a week ago, please have a look at: nuxt/nuxt#19230

My proposal would be: untangle the whole websocket stuff from nuxt core/vite and just put a proxy in front of nuxt for your websocket needs. This fixes all docker port sharing issues and you have full control that the HTTP UPGRADE comand works.

zyyv pushed a commit to zyyv/devtools that referenced this issue Mar 14, 2023
Co-authored-by: Renovate Bot <bot@renovateapp.com>
@drennvinn
Copy link

I think it's related.. I just got "WebSocket disconnected" just after installing and enabled the nuxt3-socket.io module.
if I comment "nuxt3-socket.io" in modules:[] it works again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants