Cannot connect to Node WebSockets deployment - even with custom domain
Very basic server:
I connect in the client with
There is no error message but also no
console.log()
that a connection has been established. Neither on the client nor on the server.7 Replies
Project ID:
9ebe90c5-ef7a-458e-b833-ac1fc55ce7bb
9ebe90c5-ef7a-458e-b833-ac1fc55ce7bb
const newWS = new WebSocket("ws://ws.mydomain.com:8080");
1. you arent using wss
as your schema
2. you are specifying a port in the connection string when you shouldn't be
websockets does absolutely work on railway, if you dont belive me, check for yourself
wss://utilities.up.railway.app/ws
Hey Brody, thank you for getting back to me. I have changed the connection string and it's still not working. At least throwing an error this time.
The server code is very basic - just what I posted above. It works fine in localhost so not sure what to change about it. The subdomain was set using the CNAME record provided by Railway. Interestingly, I have to explicitly define the port 8080 in order to connect to it in localhost (
ws://localhost:8080
). With the deployed version it works neither with nor without the port defined.when running on railway you want to be listening on the environment variable PORT
you may be starting a websockets server, but this is plenty similar
https://docs.railway.app/troubleshoot/fixing-common-errors
Thank you, that solved it. 🙂 Is this a common code pattern when using a PAAS provider? I would've never thought about this as the problem. Maybe the build process could look out for this and throw an error 🙂
some PAAS platforms will auto scan your app for the port its listening on and update itself, railway doesn’t do this and in a way i guess expects you to read the documentation