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
6 Replies
7 days ago
Hey there! We've found the following might help you get unblocked faster:
🧵 Unable to call api of backend-service from frontend-service via internal railway network
🧵 [NextJS] Fetch request failing when fetching API from it self
If you find the answer from one of these, please let us know by solving the thread!
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.
6 days ago
For example, I have these envs do I change or do I add railway provided variables.
Attachments
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.
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 thisconst 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.