Using internal networking to communicate with Websocket
Project ID: 2818bb01-9898-4d1c-8065-06e6404b3ed8
Hi folks, suspect I'm doing something particularly silly, but I have a React app hosted on Railway which connects to a websocket server deployed in the same environment as follows:
I notice that when I use the internal networking URL to connect to the websocket server, e.g.
Intialization fails:
Should this be possible? At least locally, if I use the Railway generated public URL of the Websocket server, the Websocket initialization and connection works fine.
61 Replies
Project ID:
2818bb01-9898-4d1c-8065-06e6404b3ed8
Apologies, but as I don't seem to be able to edit this post, I have to make clear. I don't any longer explicitly add the port to the Websocket URL, this was something I was trying but doesn't make a difference. Now I'm targeting
wss://relevant-transcription-server.railway.internal
ws://relevant-transcription-server.railway.internal:<the port your service runs on>
ws
because this is a local network, ssl is not involved
you need a port, since this is a local networkI see, that makes sense. Thanks Brody, I'll give it a try.
sounds good
Interesting, I'm now seeing:
are you trying to call the internal url from a client side app?
Yes
thats not quite how it works, its an internal url, only other services from within in the project can call it, a users browser cant call a private address, wouldnt be very private if that where the case
youd need to use the public domain, and in that case you do need to use
wss
and dont specify a portSure, will do. Just need some way of restricting access to the public URL then, but I'll look into that.
bearer tokens if thats an option
Rather, to the service at the public url*
no clue what youre trying to host on the url
yeah i mean the service is only public on the endpoints you specify yourself
remember what i said about not overcomplicating things
KISS (google it)
is a bearer over complicating it
π
All good, thank you guys
im gonna work on this thanks for the critic
i havent been helping around in tickets for as long as u have
so you have an advantage πΆπΆπΆπΆπΆ
Hi , I am noticing the socket doesn't initialise with the wss:// url within the React app deployed on Railway, yet it does if I use this URL locally.
Any intuition as to why this could be?
can you send a link to your site where i can see this error take place?
If I use the URL locally in the context of my app or in e.g. Postman, the connection is initialised immediately and no issues
yo that sounds like a super cool product btw
hmmm i can connect to it with postman just fine
Oh, interesting, I don't have an issue
damn it
what a typo
what kind of frontend app is this?
What kind? Javascript, React, uses an Express backend server, was set up with create-react-app
send me your package.json?
do you have a caddyfile
Based on what Google tells me that is I do not π
okay lets get you one then
https://github.com/brody192/create-react-app-starter
copy the nixpacks.toml and Caddyfile from that repo into yours
Ok, done. Do you suspect this is an issue with react-scripts?
i do,
react-scripts start
starts a dev server, and you wouldn't belive how strange this can behave when deploy to railway like thatCan I redeploy with those files as they are or should I read through the repo and try to adapt to my project?
they should work out of the box with your project
though wouldn't hurt to read the readme.md
Giving it a shot, seems like I should add that the way I serve is I build the frontend part of the repo and then have the backend express server serve the build folder
The higher level package.json (above the frontend and backend in the repo) is
I serve the frontend from express like this:
Not sure that we are starting a react-scripts development server in this case?
oh my bad I thought these where separate services, you definitely don't want to serve your app from express like that
do you think you could share your repo?
Sent you an invite on gh
do you have two services in your railway project?
3 - the main app is /frontend and /backend (1 service), then /nlp-api and /transcription-server are 2 separate services
okay perfect
Branch for nonprod deployment is nonprod btw (sorry if obvious)
put the nixpacks.toml and Caddyfile into the frontend folder, then in the service settings for the frontend set the root directory to /frontend
thank you, I'm very new to github
By setting the root folder to /frontend, aren't I cutting out the /backend stuff (Express server) completely?
you said you had 3 services in your railway project right?
one for the frontend, one for the backend, and another for nlp-api
the service for the backend would be express, and it's root directory would be set to /backend
No, the frontend build is served via the backend in 1 Railway service, then the nlp-api and transcription-server are served in 2 other services. I could set things up as you suggested.
it would be best to set things up as I suggested, doing it your way can be prone to issues, plus it's much neater and easier to maintain this way
Sure thing!
that means you can also remove the app.use static thing from your backend
but let me know when you have that setup or if you run into any problems!
Will do, thanks very much for your help
Hi, I separated the frontend and backend into separate services and have them working locally. I created a new service for the frontend pulling from my dev branch and am now getting this error during the deployment process.
Checking the metrics for memory usage it seems to be at max 2MB, I don't see it peaking out.
I added the Caddyfile and nixpacks.toml to frontend but it's still starting the development server. This must be because the services are containerised, my run command is yarn start, and the start script in package.json is react-scripts start.
Wonder if this could have something to do with it? Should I change the startup command?
can you link me the repo i lost the link lol
https://github.com/masoncusack/relevant - working branch is fix/breakup-frontend-backend
that error above, its coming from the frontend?
Yes
also build and deploy logs for the frontend please
you have the log downloader right?
Log downloader?
sorry, thought i gave this to you https://bookmarklets.up.railway.app/log-downloader/
delete the dockerfile from the frontend
Working π I'll try and wire up the networking again
sounds good
All looks to be working, thanks very much π
awsome!
happy to help