Using Railway private networking
Railway (mandatory referral link) has 2 different networking systems:
- a public network
- a private network
The public network gives you a public URL that can be referenced from anywhere.
The private network is a URL that’s private, internal to Railway.
The big benefit of the private network is that a service is inherently more secure if not accessible through the public Internet if not needed.
But on top of that, you got this huge advantage: using the private network does not have a cost, while public network incurs in egress fees ($0.10 / GB).
So by using the private network things are more secure, and cheaper to host.
For a while I had trouble using Railway’s (and Fly.io’s) private networking to connect my app with PocketBase but eventually I discovered the problem and since this might be something you can stumble upon too, let me explain.
When using the public network, you get a URL like
<custom_subdomain>.up.railway.app
In your app, you connect to this using
https://<the url>
With private networking you get a URL like this:
<custom_subdomain>.railway.internal
In your app, you must use the PORT as well. This is the internal port exposed by your Docker container.
In my case I used 8080, so I had to use this URL in my app:
<custom_subdomain>.railway.internal:8080
Super important: use http:// and NOT https:// or the internal network will not work.
You typically use variable references on Railway to avoid hardcoding the variables, so you can write your variables as something like:
POCKETBASE_URL=http://${{pocketbase.RAILWAY_PRIVATE_DOMAIN}}:${{pocketbase.PORT}}
assuming PORT was defined as a PocketBase service variable on Railway.
download all my books for free
- javascript handbook
- typescript handbook
- css handbook
- node.js handbook
- astro handbook
- html handbook
- next.js pages router handbook
- alpine.js handbook
- htmx handbook
- react handbook
- sql handbook
- git cheat sheet
- laravel handbook
- express handbook
- swift handbook
- go handbook
- php handbook
- python handbook
- cli handbook
- c handbook
subscribe to my newsletter to get them
Terms: by subscribing to the newsletter you agree the following terms and conditions and privacy policy. The aim of the newsletter is to keep you up to date about new tutorials, new book releases or courses organized by Flavio. If you wish to unsubscribe from the newsletter, you can click the unsubscribe link that's present at the bottom of each email, anytime. I will not communicate/spread/publish or otherwise give away your address. Your email address is the only personal information collected, and it's only collected for the primary purpose of keeping you informed through the newsletter. It's stored in a secure server based in the EU. You can contact Flavio by emailing [email protected]. These terms and conditions are governed by the laws in force in Italy and you unconditionally submit to the jurisdiction of the courts of Italy.