Private networking - I'm going insane

2 years ago

I'm trying to get private networking up and running for my react app. When setting an env variable, it doesn't seem to be registering.

project id: b3614c25-edc6-4752-b27d-9abc10f5adcf

Solved

125 Replies

2 years ago

I don't understand javascript


2 years ago

or private networking


2 years ago

I have another service that should hit the api on startup, then close gracefully. It crashes

1331048345593974874


2 years ago

fancy meeting you here


2 years ago

what kind of react app?


2 years ago

uhh


2 years ago

website?


2 years ago

I started with your template


2 years ago

Okay, realizing I may be stupid and private networking won't work because it's a frontend


2 years ago

But that doesn't explain why the environment variable isn't working


2 years ago

Or why my other service can't hit the api


2 years ago

depends, if it's vite, then the variable needs to be prefixed with VITE_ if it's create-react-app then the variable needs to be prefixed with REACT_APP_


2 years ago

you might not be listening on IPv6? or you aren't specifying the port in the url, or both?


2 years ago

Should be listening on IPv6?


2 years ago

1331061015261089922


2 years ago

Damn. I thought that was a weird convention, will put it back


2 years ago

yep that should do it, what is the full url you are trying to call?


2 years ago

that's fair tbh, it's tripped me up too



2 years ago

do you have a PORT variable set to 5000?


2 years ago

Yep


2 years ago

okay, and is this gunicorn app in the same railway project?


2 years ago

Oui


2 years ago

okay, what exactly is trying to make the request? the fetch API from nodejs? fetch in a web browser?


2 years ago

I'm not too familiar with js so don't know the specifics, but here's a code snippet

1331061947831025764


2 years ago

1331061979397492829


2 years ago

Just updated the var name


2 years ago

Getting somewhere!

1331062192933572739


2 years ago

If I have to use the public URL because of my implementation that's fine. It's not sending a ton of data


2 years ago

oh so this is a request from the web browser?


2 years ago

Yeah


2 years ago

There's also a request from another python service that's not working


2 years ago

From the screenshot up here


2 years ago

if this is a browser trying to make the request, you need to use the public url


2 years ago

Super simple code + some stackoverflow stuff that should force ipv6

1331063143530762341


2 years ago

just do BACKEND_URL + "/setupCron"

and set the backend url to include the http:// and port part


2 years ago

Testing that now


2 years ago

1331064902676381716


2 years ago

and that url leads to the app shown here?


2 years ago

Yes


2 years ago

and that app that is calling it, is in the same project right?


2 years ago

Yep


2 years ago

wait... what


2 years ago

1331069440191893574


2 years ago

Why does it print the full url earlier but not here


2 years ago

there's no syntax difference between the two f strings


2 years ago

lol python is fun


2 years ago

1331070318676152371


2 years ago

1331070385898258454


2 years ago

What the hell


2 years ago

remove that family stuff


2 years ago

Just did, didn't work


2 years ago

Gonna be honest here, I've literally never gotten the private network to work


2 years ago

Now, a couple times was because I didn't know you couldn't call it from a react service, which makes total sense now that I think about it


2 years ago

But it's just funky


2 years ago

IPv6 can be tricky


2 years ago

It should be ipv6 with the family stuff enabled, HAS_IPV6 is true


2 years ago

Will keep looking into it


2 years ago

I'll give your project a look over when I'm back at the laptop


2 years ago

project id please


2 years ago

b3614c25-edc6-4752-b27d-9abc10f5adcf


2 years ago

1331075797804646551


2 years ago

i lied


2 years ago

you forgot --bind


2 years ago

ah shit


2 years ago

my bad


2 years ago

You're good I'm the one who forgor


2 years ago

this is returned in an api call the dashboard makes, wish it was made visible in the product for the user to see somehow


2 years ago

It worked! Thanks for helping fix such a stupid mistake lol


2 years ago

I have a ticket to track how many times I have to look at sockets.ipv6 lol


2 years ago

hopefully if it gets enough traction the information can be exposed to the end user


2 years ago

Yeah that'd be very nice. At least as a warning near the private url


2 years ago

it gets a little tricky since a service can listen on multiple ports


2 years ago

I thought that the proxy sends all requests to one port?


2 years ago

yeah the public proxy, but we are talking about the private network


2 years ago

Ah I figured that it worked much the same


2 years ago

nope, no proxy internally


2 years ago

There are decent docs on how to use it, but no specifics about how it actually works in comparison to the public network


2 years ago

just works like a local area network, with a nice domain and IPv6 only


2 years ago

So all services effectively just take different ports within the .railway.internal host? I'm assuming that two services can't have the same port then


2 years ago

Not sure if that's documented


2 years ago

two services can have the same port, services listen on whatever port they listen on and are accessible on whatever port they do listen on


2 years ago

literally think of it as a LAN network


2 years ago

So if two services have the same port, they'll both recieve requests meant for the other?


2 years ago

I'm not sure what the LAN behaviour for that is lol


2 years ago

no, they will receive the traffic that is destined to them


2 years ago

internally your app does a DNS lookup, gets the IP and then sends the traffic to that IP and port


2 years ago

Will they not both be assigned HOSTNAME:5000 (for example) if they both have the same port?


2 years ago

they are separate services though


2 years ago

How does the origin know which service to send to?


2 years ago

Right, but they share a port


2 years ago

so? they have different IPs


2 years ago

If the only point of reference is the port number, I don't see how the IP comes into play


2 years ago

are we talking about traffic coming in publicly or privately?


2 years ago

privately


2 years ago

If service A wants to send to service B, but service B shares a port with service C. Service A sends a request to HOSTNAME:PORT


2 years ago

then it does a DNS lookup for the host, gets its IP, and then sends the data to that IP + port, each service has its own IP


2 years ago

But how would it know which service to send to, there's no identifier that would tell one from the other


2 years ago

the IP is the identifier


2 years ago

I get that each service has its own IP, but if both are listening on HOSTNAME:PORT how does the origin's code know which IP to send to


2 years ago

whatever IP was returned from the DNS lookup


2 years ago

That's not answering my question


2 years ago

Let's say we have 3 services. Two are listening on project.railway.internal:5000. The third sends a request to project.railway.internal:5000


2 years ago

Which service does the third send the request to


2 years ago

I'm not understanding how the issue of two services sharing a port is resolved


2 years ago

you just gave me the same 3 domains?


2 years ago

I did, two are listening on the same port on the private network


2 years ago

you can't have the same domains


2 years ago

domains need to be unique per environment


2 years ago

So two services on the private network cannot listen on the same port?


2 years ago

they can listen on the same ports, they just can't have the same domain


2 years ago

But will their hostname not be the same? I thought that was unique per project


2 years ago

Assuming two services in the same project


2 years ago

no, every service in an environment will have a unique domain


2 years ago

Ah there we go that's what I was missing


2 years ago

I mean it's the same for the public network


2 years ago

I made an assumption based on the private network hostname for the backend api we worked out last night

1331287200909754379


2 years ago

my bad


2 years ago

two people can't own google.ca at the same time, legal reasons aside


2 years ago

lol right


2 years ago

looks like you changed the service name and left the private domain as it was originally


2 years ago

you would not be able to make another service with the same private domain, it would get a different domain


2 years ago

Makes sense


2 years ago

feel free to mark as solved if you dont have anymore questions 🙂


2 years ago

!s


Status changed to Solved adam • over 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...