You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
question: Running on the same port as an HTTP server #173
Hi, I'm developing a project people will self-host, and for simplicity it would be better if I could run the websocket server on the same port as my main application. Is there a way to just get a request handler from this library?
Hey @alexgleason, currently there is no way to get a request handler from this library. I'd like to help further, but without much context, I won't be able to provide a working solution that could fit your needs. If your main application is using an HTTP server you control (e.g., an API backend you're writing), you should be able to add an endpoint to the API that takes requests and upgrades them to websocket connections. This would be done on the same port.
Activity
crookse commentedon Apr 7, 2023
Hey @alexgleason, currently there is no way to get a request handler from this library. I'd like to help further, but without much context, I won't be able to provide a working solution that could fit your needs. If your main application is using an HTTP server you control (e.g., an API backend you're writing), you should be able to add an endpoint to the API that takes requests and upgrades them to websocket connections. This would be done on the same port.
alexgleason commentedon Apr 7, 2023
Thank you @crookse. I'm wanting to use this library with a Deno HTTP server such as Hono or Oak. Something like this maybe?
This example exposes a
handlerfunction on the Server object, with a type like(req: Request) => void. You would use instead of callingserver.run().For prior art, socket.io seems to offer an API like this (but socket.io is not compatible with normal websockets, making Wocket the better option): https://github.com/socketio/socket.io#in-conjunction-with-express
The reason I want to use this library instead of something custom is so I could leverage the powerful channels and broadcast APIs.
Also, my code is here: https://gitlab.com/soapbox-pub/ditto/-/blob/develop/src/app.ts