Webserver and Services Interacting Within The Private Network

2 years ago

I've got a simple question that requires this help thread.

I've got a Go webserver that I used the Echo library and listened to on the private network at

app.Start("private-service.railway.internal:80" )

And another separate service using NodeJS to fetch content through this network using

fetch("private-service.railway.internal")
// Then logic

The question is is this how you tell your service to listen to the private network (the port 80 is using Railway's environment variable that was injected I just placed it there for convenience) and how you communicate through the private network?

Closed

33 Replies

2 years ago

N/A


2 years ago

I'm just asking this because apparently I'm getting quite a lot of egress.

I'm not sure if this is a result of Caddy (yes I run Caddy that proxies a certain file folder as a static webserver to the public network) having a random weird egress.


2 years ago

Echo is stdlib, so the following code should suffice to listen on IPv6.

port := cmp.Or(os.Getenv("PORT"), "8080")

app.Start((":" + port))

2 years ago

@RyanKnack - for visibility


2 years ago

Wouldn't this also bind to the public network? Because this one service has both private and public networking enabled.

The private should only be for the echo API and the public is for the Caddy API


2 years ago

yes, if you don't want to expose the app then don't add a domain to it


2 years ago

Oh so what you mean is I can just onit the hostname, but proxy the requests through the service settings network instead?


2 years ago

And then in a separate service I can call it even it without being binded to the private network?


2 years ago

I think I'm missing some much needed context here


2 years ago

Ok

There are 2 services, service A and service B

Service A makes a fetch request to service B, through the private network to reach service B's echo API (through port 80).

Service B has the echo API, which should ONLY be exposed to the private network (so service A can communicate with service B). Service B also has a Caddy static server that I expose to the public network (through the service settings through port 8081)

I want to know if the above, https://discord.com/channels/713503345364697088/1293340927024173181/1293340927024173181, is the correct way to do it


2 years ago

in this story, the code you showed above, what service is it in?


2 years ago

Go code is in service B, nodeJS fetch code in service A


2 years ago

does service B need to be connected to over the public network?


2 years ago

Yes, but only through port 8081 for the Caddy server


2 years ago

it's a go app, how is it also caddy?


2 years ago

I run two simultaneous scripts


2 years ago

Like go run server.go & caddy run


2 years ago

why aren't those broken out into two railway services?


2 years ago

I needed to store temporary files in the ephemeral disk, because I couldn't share volumes across services


2 years ago

alright fair enough


2 years ago

alright then if you don't want the go app to be publicly exposed, simply don't publicly expose it


2 years ago

assuming this is valid, this is what you want to use


2 years ago

So without adding the host it will be private?


2 years ago

And still reachable by service A?


2 years ago

correct


2 years ago

Aight awesome I'll try it out later


2 years ago

sounds good


2 years ago

Ok I've done that and now the app bounds itself to both the private and public network. If I'm not mistaken all I have to do is just to not add a route from the service settings to the public port right?


2 years ago

correct


2 years ago

So with the egress issue as long as I call the endpoint http://private-service.railway.internal all happenings will happen over the private network despite the Go webserver bounded by both, so not incurring egress costs?


2 years ago

you need to use the port too, but yes


2 years ago

Oh I thought http defaults to port 80 so I didn't have to <:kekw:788259314607325204>


2 years ago

it does, but it's best to not listen on a privileged port


Welcome!

Sign in to your Railway account to join the conversation.

Loading...