How to communicate between two apps on internal network
nahasco
HOBBYOP

a month ago

I have a django app that accepts rest api requests and a react frontend on the same railway project. Using the public domain of django I can seemlessly call fetches and get the data I need. I am trying to use the internal network though for better speed and security but wasnt able to get it to work.

I simply added the priate domain of django to the django allowed hosts, and the react private domain to the allowed origins and csrf. Then I called the domain using fetch in react with http://.

But I then get timout errors. What am I missing here?

44 Replies

Private networking URLs are structured as .railway.internal.


(no markdown available for this content)


nahasco
HOBBYOP

a month ago

Thats what I used


nahasco
HOBBYOP

a month ago

Do I need to specify the port or something else?


Yes.



nahasco
HOBBYOP

a month ago

Backend is called backend and react is called dashboard

image.png

image.png


You used https.


Also, you can’t use private networking for frontend code.


Clients (machines that access your website) do not have access to private networking.


nahasco
HOBBYOP

a month ago

The dashboard domain is using http


nahasco
HOBBYOP

a month ago

I am calling it through a proxy on the server


nahasco
HOBBYOP

a month ago

So it is not directly called from the client, the client calls the internal proxy and the proxy calls the backend


nahasco
HOBBYOP

a month ago

I see the https let me fix that


nahasco
HOBBYOP

a month ago

Do I have to add the port too?


Yes.


nahasco
HOBBYOP

a month ago

is it 8080 be default?


This depends on what port your application is listening to.


nahasco
HOBBYOP

a month ago

Thats right


nahasco
HOBBYOP

a month ago

With all that I get the timeout error


nahasco
HOBBYOP

a month ago

(no markdown available for this content)

Attachments


nahasco
HOBBYOP

a month ago

What could be the cause of a timeout?


Either the application didn’t respond (wrong port?) or your proxy couldn’t resolve it.


I assume the frontend is able to reach the proxy successfully?


nahasco
HOBBYOP

a month ago

Yes, when using the public domain everything works


nahasco
HOBBYOP

a month ago

the simple swap to private doesnt work


Try SSH-ing into your proxy service and curl -I your private networking URL and see if it can get a OK head response.


Right click on your service and Copy SSH Command to get the SSH command. You’ll need Railway CLI installed to use this.


nahasco
HOBBYOP

a month ago

root@d4c0178c0e9c:/app# curl

bash: curl: command not found


nahasco
HOBBYOP

a month ago

getting this, tried installing with apt but

root@d4c0178c0e9c:/app# apt install curl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package curl

nahasco
HOBBYOP

a month ago

okay tried node

root@d4c0178c0e9c:/app# node -e "require('http').get('http://backend.railway.internal:8080', (res) => console.log(res.statusCode))"
301

nahasco
HOBBYOP

a month ago

got a 301


Right. Sorry.


Are you able to see where it’s trying to redirect you to?


(I assume you redeployed your service after updating variables?)


nahasco
HOBBYOP

a month ago

I did update them


nahasco
HOBBYOP

a month ago

I think it could be redirecting to https


nahasco
HOBBYOP

a month ago

(no markdown available for this content)

Attachments


nahasco
HOBBYOP

a month ago

full response


nahasco
HOBBYOP

a month ago

Might be django doing it


nahasco
HOBBYOP

a month ago

Ill update the force ssl bool in django


nahasco
HOBBYOP

a month ago

Okay that was it


nahasco
HOBBYOP

a month ago

The issue was SECURE_SSL_REDIRECT defaulting to True in the django settings


nahasco
HOBBYOP

a month ago

Good to know for anyone trying to use the internal network with django


Welcome!

Sign in to your Railway account to join the conversation.

Loading...