expose HTTP + Websockets for (rather monolithic) Node.js-Application

Hello everyone. I'm currently trying to set up a nest.js app that uses both https and wss on differend endpoints (eg: "/items", "/realtime"). Locally, I just used two different ports for http and ws. What's the easiest way to make it work on railway, ideally with one url (api.example.com) where the protocol corresponding to the endpoint can be used? Thank you for your help!
5 Replies
Percy
Percy11mo ago
Project ID: 7e07ecbc-0807-492d-b96b-270cfda10eeb
leonceaklin
leonceaklin11mo ago
7e07ecbc-0807-492d-b96b-270cfda10eeb
Brody
Brody11mo ago
I'm confused, if they're on different endpoints what's the problem? that's the recommended way to do it
leonceaklin
leonceaklin11mo ago
Hey there, You are absolutely right of course. I just needed to configure my nest.js application differently, mainly by NOT specifying the port in the @WebsocketGateway() explicitly in nest.js. Otherwise you get an EADDRINUSE error, which made me think that ws and http is not possible on the same port. I also needed to specify a path for WebsocketGateway to have a specific endpoint:
@WebsocketGateway({
path: '/realtime'
})
@WebsocketGateway({
path: '/realtime'
})
The connection is now possible through this exact path. Thank you for pointing out that running http and ws on different endpoints is indeed possible.
Brody
Brody11mo ago
awesome, so all solved?