Open pi0 opened 9 months ago
After reviewing the Netlify documentation, I found no suitable offering that will properly support websocket servers at this time.
Thanks for your investigation. Re Netlify, i have reached out and waiting for an answer if there is any viable current or future plans.
Is websocket still not available in the current development mode of the latest nuxt?
I try to access /websocket in development mode (pnpm run dev) and it's always connecting.
If I compile and start with node .output/server/index.mjs
everything works fine.
https://github.com/StringKe/report-nuxt-webscoket
- Operating System: `Darwin`
- Node Version: `v21.5.0`
- Nuxt Version: `3.10.3`
- CLI Version: `3.10.1`
- Nitro Version: `2.9.3`
- Package Manager: `pnpm@8.15.4`
- Builder: `-`
- User Config: `nitro`
- Runtime Modules: `-`
- Build Modules: `-`
@StringKe You need to use nuxi-nightly
.
Are there plans to let us define which adapters defineWebsocketHandler
uses internally?
Specifically, in my case I want to use the crossws uWs
adapter
Or is it possible to just import it manually and use it instead of defineWebsocketHandler
?
uws
requires it's own server preset for Nitro to be supported. (because it is not based on node:http
)
does crossws have an API to proactively close connection?
Does nuxt support websocket when deployed on cloudflare pages? Everything is fine on localhost, but on Cloudflare I'm getting only status finished
Hello, I am trying to combine peer-server with my Nuxt application. Unfortunately, it doesn't work as expected. The reproduced issue is in nuxt/nuxt
In the peer-server middleware, ws
is used to send the WebSocket message
https://github.com/peers/peerjs-server/blob/master/src/services/webSocketServer/index.ts#L59
import { WebSocketServer as Server } from "ws";
const options: WebSocket.ServerOptions = {
path: this.path,
server,
};
this.socketServer = new Server(options);
this.socketServer.on("connection", (socket, req) => {
this._onSocketConnection(socket, req);
});
Currently, Nuxt is unable to listen for web socket connection events as expected
Does nuxt support websocket when deployed on cloudflare pages? Everything is fine on localhost, but on Cloudflare I'm getting only status finished
Hi did u manage to get this fixed?
Thanks for your investigation. Re Netlify, i have reached out and waiting for an answer if there is any viable current or future plans.
Hi, @pi0 any updates on this from the netlify team?
For netlify, you might use SSE (long polling) as much as know. @serhalp might give better answer if there is any plans for future WebSocket API.
👋🏼 I'm not aware of any plans to change Netlify's support for WebSockets. However, Server-Sent Events (SSE) work great with Netlify Edge Functions.
@pi0 is there an example somewhere that instructs how to set up websockets with the cloudflare-module
Nitro preset?
When using the example from the docs, if I run locally in Nuxt (via nuxt dev
) the tabs communicate properly; however, when I build and then run wrangler dev
there is no communication between separate tabs.
I can see each peer
is available (the number is incremented for each connected client if I output on the page) but I can not receive messages between them after calling subscribe/publish
accordingly.
I see the following note on the CrossWS Pub / Sub
page:
Native pub/sub is currently only available for Bun, Node.js (uWebSockets) and Cloudflare (durable objects)
but there are no instructions as to how to actually hook it up (here in the Nitro docs) to Cloudflare Durable Objects?
If you can point me in the right direction I can also push up a PR for docs.
Alternatively, if you have another (non-experimental) suggestion on how to implement similar messaging, I'd be open to try.
Durable-ojbect support is on the progress (sorry for misleading docs, that section is not released yet)
Durable-ojbect support is on the progress (sorry for misleading docs, that section is not released yet)
😅 Well I feel better that I couldn't get it working now. Tag me if I can help test/implement/document
Hello, is there a way to access the event similar to defineEventHandler or eventHandler in Nuxt? I'm asking because I'm trying to retrieve a router parameter, and all server utility functions require the event parameter.
Hello, is there a way to access the event similar to defineEventHandler or eventHandler in Nuxt? I'm asking because I'm trying to retrieve a router parameter, and all server utility functions require the event parameter.
A route parameter from the websocket route? what's your use case?
I'm trying to create a proxy for Parse Server's LiveQueries and need to pass parameters to initialize the SDK and perform the necessary queries. I'm not sure if this is the best approach, as I'm just starting out with WebSockets.
Yeah, if it possible, please: add possibility to read params from url. It's might be useful to authenticate user with one-time/signed token.
Possible solution may be second (or first, ws still experimental feature anyway) argument to open()
hook
UPD:
it's possible to parse params from peer.url
string:
export default defineWebSocketHandler({
open(peer) {
console.log(peer.url); // `/some/usr/TOKEN/ws`
},
});
What about platforms not mentioned, (e.g. Azure) are they omitted for any reason?
@pi0 is there an example somewhere that instructs how to set up websockets with the
cloudflare-module
Nitro preset?When using the example from the docs, if I run locally in Nuxt (via
nuxt dev
) the tabs communicate properly; however, when I build and then runwrangler dev
there is no communication between separate tabs.I can see each
peer
is available (the number is incremented for each connected client if I output on the page) but I can not receive messages between them after callingsubscribe/publish
accordingly.I see the following note on the
CrossWS Pub / Sub
page:Native pub/sub is currently only available for Bun, Node.js (uWebSockets) and Cloudflare (durable objects)
but there are no instructions as to how to actually hook it up (here in the Nitro docs) to Cloudflare Durable Objects?
If you can point me in the right direction I can also push up a PR for docs.
Alternatively, if you have another (non-experimental) suggestion on how to implement similar messaging, I'd be open to try.
hey, currently i'm also facing the same issue, connections works pretty well in local dev nuxt dev
. However can't see incoming data when running with wrangler dev
. Any lead on this ?
Initial PR: https://github.com/unjs/nitro/pull/2170
Relavant docs:
Platform support
bun
cloudflare-pages
cloudflare-module
cloudflare
(worker)deno-deploy
deno-server
node-server
node
viawebsocket
exportnode-cluster
Needs investigation:
aws-lambda
netlify-edge
netlify-lambda
stormkit
vercel-lambda
vercel-edge
wnterjs
zerabur