Using Railway’s Internal Netwrok
avenue-ticketing
PROOP

4 months 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

4 months 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
HOBBY

4 months ago

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


noahd
EMPLOYEE

4 months ago

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


noahd

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

avenue-ticketing
PROOP

4 months ago

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

Attachments


fra
HOBBY

4 months 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
HOBBY

3 months 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.


Loading...