Webserver and Services Interacting Within The Private Network

a year 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?

33 Replies

a year ago

N/A


a year 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.


a year ago

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

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

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

a year ago

@RyanKnack - for visibility


a year 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


a year ago

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


a year ago

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


a year ago

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


a year ago

I think I'm missing some much needed context here


a year 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


a year ago

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


a year ago

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


a year ago

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


a year ago

Yes, but only through port 8081 for the Caddy server


a year ago

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


a year ago

I run two simultaneous scripts


a year ago

Like go run server.go & caddy run


a year ago

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


a year ago

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


a year ago

alright fair enough


a year ago

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


a year ago

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


a year ago

So without adding the host it will be private?


a year ago

And still reachable by service A?


a year ago

correct


a year ago

Aight awesome I'll try it out later


a year ago

sounds good


a year 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?


a year ago

correct


a year 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?


a year ago

you need to use the port too, but yes


a year ago

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


a year ago

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


Loading...