apteryxxyz / next-ws

Add support for WebSockets in Next.js app directory.
https://npmjs.com/next-ws
171 stars 12 forks source link

How to use next-ws/client to connect to a websocket server in nestjs? #11

Closed DanielXavierJob closed 9 months ago

DanielXavierJob commented 9 months ago

I currently have a websocket server built in nestjs, and I would like to connect using nextjs-ws because from what I've seen, it is more robust in client connections and would eliminate the need to create the complete websocket code in nextjs, but the problem I have facing is that it does not accept websocket connections using http/https, only ws and wss

I would like to know if there is any way around this

apteryxxyz commented 9 months ago

Next WS's purpose is bringing a WebSocket Server to the Next.js app directory. The core Next WS package includes some client-side code that’s super straightforward and designed for a quick connection to the WS server. It’s pretty concise, just 60 lines in a single file. This client code isn't the main focus of the package and isn't really meant to be used by itself. If you need something more specialised, you might want to look for a dedicated package.

The mentioned client code can be found at https://github.com/apteryxxyz/next-ws/blob/main/packages/core/src/client/context.tsx, if that is all you need, you're welcome to paste it into your project and make any changes you want.