websocket

I'm trying to have my real-time chat that is using websockets work with Railway with SSL. It's a Django project and I've deployed it to my custom domain that's using https. I can't find anything online about how to configure wss server-side for railway. It's not like I have access to Nginx and can write the config for this. It just says it can't find/create a connection to the websocket server and is trying wss://. My chat is also using Redis that I spun up on railway but I don't think that should be an issue.
Solution:
dont know if thats how it works, you may need to use daphne instead of gunicorn
Jump to solution
21 Replies
Percy
Percy6mo ago
Project ID: 1ba89116-6373-47f4-9cf9-785a08acae4c
Drekkenz
Drekkenz6mo ago
1ba89116-6373-47f4-9cf9-785a08acae4c I don't need an additional CNAME or anything for this protocol do I?
Brody
Brody6mo ago
railway does all ssl for you, all you need to do is connect to your websocket endpoint with wss:// and port 443 the app itself has to have the http server and websocket endpoint on the same port
Drekkenz
Drekkenz6mo ago
Ok I'll look into how to change http to be 443
Brody
Brody6mo ago
that's not quite what I meant your app should listen on the PORT environment variable (not 443), but you will connect to the app externally from 443
Drekkenz
Drekkenz6mo ago
Okay so it'll just be something like this wss://your_domain.com:443/your_websocket_endpoint. Just a port change
Brody
Brody6mo ago
well technically you're using wss:// so 443 is implied, specifying it there is a bit redundant
Drekkenz
Drekkenz6mo ago
It's already using that without the explicit port though? Not sure why it can't get it and what needs to be configured
Brody
Brody6mo ago
show me the current url for the websocket that your app is trying to connect to
Drekkenz
Drekkenz6mo ago
wss://decisionchess.com/ws/chat/c5d534db-b06a-4063-81f2-bacf467996b7/
Brody
Brody6mo ago
i got a 404
Drekkenz
Drekkenz6mo ago
I'll see if I need to update any settings or routing for production
Brody
Brody6mo ago
i get this on your site
No description
Drekkenz
Drekkenz6mo ago
That's a different websocket and I connect to that one just fine on the site
Brody
Brody6mo ago
alright
Drekkenz
Drekkenz6mo ago
Also that may just be because Django crashed for a bit lol Ahh I think I may know why I've updated it to use asgi for the new websockets so my procfile is now old web: python manage.py collectstatic --noinput && gunicorn decisionchess.wsgi --log-file - I'm guessing just replace it with .asgi
Solution
Brody
Brody6mo ago
dont know if thats how it works, you may need to use daphne instead of gunicorn
Drekkenz
Drekkenz6mo ago
Might look into it after trying this, it looks like it's trying to use my new asgi file with that change but early imports don't work as the apps aren't fully loaded yet
Brody
Brody6mo ago
gotcha
Drekkenz
Drekkenz6mo ago
Daphne worked! Tried marking solution but it's not letting me Thanks
Brody
Brody6mo ago
no problem!