Socket.io not working

robsheelyHOBBY

5 months ago

I've added socket.io to my node/express app. The http server is on port 5173 and it works fine. The socket.io server is on port 3000 and it looks like my client requests aren't getting through. I've looked through the documentation and setting port variable and I can't figure out how to apply it in this case.

I don't see a configuration option for opening a second port. Is that what I need? Or is there soething else I'm missing?

Thanks!

3 Replies

5 months ago

A second port would need to be exposed via a custom domain using target ports -

https://docs.railway.com/guides/public-networking#target-ports


robsheelyHOBBY

5 months ago

Thanks for your quick response.

I hate to be dense, but socket.io isn't hitting a subdomain so I don't know how to define the port for it. Here's the URL it's trying to hit: https://manuscript-registry-demo-production.up.railway.app:3000/socket.io/.

Of course, the 3000 is arbitrary. It could be any port, but I define it as '0.0.0.0:3000' in my app and this is the URL that gets generated.


5 months ago

Instead of hitting a domain:port you would setup a domain using the target port and configure the socket.io client to connect to that custom domain.

Or, have the http and socket.io server listen on the same port.


Socket.io not working - Railway Help Station