Frontend accessing backend - internal URL?
Hi folks
I have a seperate FE and BE service - two different projects.
The FE has an env var to locate the backend.
Should I set this to the internal URL of the BE service that railway exposes?
If so, should I prefix with http/https?
37 Replies
Project ID:
c18400df-5dee-4fe7-bc56-a98db8d475bd
c18400df-5dee-4fe7-bc56-a98db8d475bd
two different projects, or two different services?
please read this page so we can get our terminology correct before going forward -
https://docs.railway.app/overview/the-basics
two different services within the same project
thank you
is this a CSR frontend?
NextJS frontend, blend of SSR/CSR
some of my build steps hit the backend, when I've changed to the internal URL (with https:// prefix) I get this:
the private network is not available during build time.
the internal domains may use domains instead of IP addresses, but they need to be treated like a local IP, meaning you use http and a port in the URL.
if your frontend calls the backend via SSR during runtime use the private network.
if a client's browser calls the backend, use the public url.
Are the IPs static on a hobby plan?
that is a pro only feature, and it doesnt have anything to do with private networking.
all makes sense, thanks Brody
let me know if you have any more questions
sorry, one more, when addressing the internal url in SSR, do I use http or https prefix?
http
treat it like your local network, but instead of a ip, it uses a domain
thanks man. Is that something that's obvious to everyone but me, or should it be in docs? (Or, is it already?)
its not obvious to everyone, i can for sure see the logic in thinking you would use https with a domain name, but it is in the docs! - https://docs.railway.app/guides/private-networking#use-internal-hostname-and-port
thanks again - should have read the manual
its not always a first thought to dig into the docs, no worries!
ok - have been trying this, on an API call that is definitely SSR
I'm calling
<my internal url>:8080/<api>
from my frontend. My backend (python) has the internal url in ALLOWED_HOSTS
I'm getting a
on the frontendplease provide the actual url you are using
DM'd
#🛂|readme #5
you need a way people can pass you variables they don't want exposed
would rather not post in public
I assure you it's not sensitive in the slightest
it wouldn't be a very private network otherwise haha
does your backend listen on 8080?
yes
gunicorn? unicorn?
verified with a print on launch of my backend -
THE PORT IS 8080
gunicorn - started with web: python manage.py migrate && gunicorn <name>.asgi:application -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:$PORT
remove the bind flag
(and it's accompanying host:port)
doing so
no joy
show me your new start command please
web: python manage.py migrate && gunicorn share_a_podcast_be.asgi:application -k uvicorn.workers.UvicornWorker
what error are you getting now
Same as above
Connection refused
very sorry, i was mistaken, your start command needs to be -
works!
Next is now giving me warnings about mixed protocols being used (https vs http)
Which I’ll look at
sounds good