Using Railway’s Internal Netwrok

avenue-ticketing
PRO

7 days ago

Is there anyway to connect the API via Railway’s Internal network instead of public network? This should save on network egress costs and also help make the system faster?

Attachments

$10 Bounty

6 Replies

Railway
BOT

7 days ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


fra
HOBBYTop 5% Contributor

6 days ago

what do you need to connect? in theory all the services have an internal link you can use


6 days ago

Yep! In your connection string just pass the private URL instead of the public! It'll work just fine.


error

Yep! In your connection string just pass the private URL instead of the public! It'll work just fine.

avenue-ticketing
PRO

6 days ago

For example, I have these envs do I change or do I add railway provided variables.

Attachments


fra
HOBBYTop 5% Contributor

6 days ago

You can add whatever env you need, just pay attention that whatever is NEXT_* can be public, so probably the stripe key shouldn't be a NEXT_ variable....


avenue-ticketing

For example, I have these envs do I change or do I add railway provided variables.

smolpaw
HOBBYTop 5% Contributor

5 days ago

No you can't use private endpoint for a variable that starts with NEXT_PUBLIC_
These variables get shipped to the client which cannot call private endpoints. They have to be public.

Something i used to do in nextjs is have 2 env vars, NEXT_PUBLIC_API_URL and just API_URL
Then i would conditionally assign apiUrl variable like this

const apiUrl = process.env.API_URL || process.env.NEXT_PUBLIC_API_URL;

This way if the api call is made during build time, public endpoint gets used. If it's made during runtime on server in SSR routes then the private endpoint gets resolved first and used.