Search code examples
node.jsherokudeploymentsocket.ionestjs

Nestjs + Socket.io - doesn't work on custom port after deploy on Heroku


I am facing an issue with my backend app on Nest.js and Socket.io after deploying on Heroku (on localhost all works), then I try to set a custom port for WebSockets from @WebSocketGateway() decorator.

When I set empty decorator like that, all is working:

@WebSocketGateway() enter image description here enter image description here

But when I set this decorator with some params (like port), and I can't connect to my ws endpoint. enter image description here enter image description here

Did someone face a similar problem?

I created codesandbox with this code - https://codesandbox.io/s/nest-socket-io-custom-options-forked-vgx238


Solution

  • Heroku doesn't expose every port, just the port assigned to the PORT env variable which is what your application should be running on. There's no way to use a custom port other than the given process.env.PORT