Private Networking Port
faeyumbrea
PROOP

9 months ago

When using private networking between services, how do I determine the port the app is listening on if no PORT variable is set in the app config?

Solved$10 Bounty

20 Replies

faeyumbrea
PROOP

9 months ago

N/A


9 months ago

The app is going to have to tell you.


9 months ago

Usually you can either define their variable or look up their documentation to find what the default is


9 months ago

Can I ask what service you're asking about?


faeyumbrea
PROOP

9 months ago

It's an axum server I wrote myself, it will obey a port variable and I know Railway sets one, I just can't reference that value in another apps config without setting it myself


9 months ago

Yeah. You'll have to set it. That's standard.


9 months ago

Also I ❤️ axum


9 months ago

Pretty sure 3000 is default


faeyumbrea
PROOP

9 months ago

3000 would be default if following the axum tutorial that is true, but it states somewhere in the railway docs that railway will set a PORT variable for networking. I guess its intended for you to set it if you need the application running on a specific port


9 months ago

Yeah, but in order to support that your app also has to be set up for it. Here's the "correct" way to do that in Rust:

let port: u16 = std::env::var("PORT")
        .unwrap_or_else(|_| "3000".to_string()) 
        .parse()
        .expect("Failed to parse PORT");

faeyumbrea
PROOP

9 months ago

Yeah, it does that, I am also creating an IPV6 tcpsocket


9 months ago

awesomesauce


9 months ago

you could use shared variables and expose the port variable?



faeyumbrea
PROOP

9 months ago

Yeah, I've gone and done that now, it was just surprising to me that the automatically attached port variable is not exposed at all, only if the user explicitly set it


9 months ago

Doesn't need to be a shared variable


9 months ago

It can just be a service variable that you reference


faeyumbrea
PROOP

9 months ago

I got it working, thanks for the input!


Status changed to Solved brody 9 months ago


9 months ago

!s


9 months ago

!s


Loading...