Publish a message on websocket from another endpoint
Hello,
I am using NuxtHub and enabled experimental websockets from Nitro and workers from NuxtHub.
I have an endpoint
server/api/ws.ts:
I would like to publish a message from another endpoint server/api/test.ts
How can I do that? Or should everything be handled in the websocket endpoint directly?
Thanks for the help.2 Replies
Hi @Tio. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I'm sorry, but the knowledge sources provided do not contain explicit information on how to publish a message to a WebSocket channel from a separate HTTP endpoint (such as
server/api/test.ts) when using Nitro's experimental WebSocket support in Nuxt or NuxtHub.
The available documentation and examples show how to handle WebSocket connections and events within the WebSocket handler itself using defineWebSocketHandler, but they do not describe a built-in or documented way to access or interact with WebSocket peers or channels from outside the WebSocket handler context (such as from a standard API route) Nuxt 3: Integrating WebSockets in Nuxt and Nitro.
If you need this functionality, you may need to look for additional Nitro or NuxtHub documentation, or consider architectural alternatives such as using a shared storage or pub/sub mechanism (like Redis) to communicate between endpoints and WebSocket handlers. However, this approach is not covered in the provided sources.
If you have access to the latest Nitro or NuxtHub documentation, it may be worth checking there for any new APIs or patterns that support this use case.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@932053571342573599> Kapa.ai is still learning and improving, please let me know how I did by reacting below.