Webserver and Services Interacting Within The Private Network

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" )
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
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?
Solution:
Echo is stdlib, so the following code should suffice to listen on IPv6. ```go port := cmp.Or(os.Getenv("PORT"), "8080") ...
Jump to solution
28 Replies
Percy
Percy2mo ago
Project ID: N/A
RyanKnack
RyanKnackOP2mo ago
N/A 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.
Solution
Brody
Brody2mo ago
Echo is stdlib, so the following code should suffice to listen on IPv6.
port := cmp.Or(os.Getenv("PORT"), "8080")

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

app.Start((":" + port))
Brody
Brody2mo ago
@RyanKnack - for visibility
RyanKnack
RyanKnackOP2mo 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
Brody
Brody2mo ago
yes, if you don't want to expose the app then don't add a domain to it
RyanKnack
RyanKnackOP2mo ago
Oh so what you mean is I can just onit the hostname, but proxy the requests through the service settings network instead? And then in a separate service I can call it even it without being binded to the private network?
Brody
Brody2mo ago
I think I'm missing some much needed context here
RyanKnack
RyanKnackOP2mo 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
Brody
Brody2mo ago
in this story, the code you showed above, what service is it in?
RyanKnack
RyanKnackOP2mo ago
Go code is in service B, nodeJS fetch code in service A
Brody
Brody2mo ago
does service B need to be connected to over the public network?
RyanKnack
RyanKnackOP2mo ago
Yes, but only through port 8081 for the Caddy server
Brody
Brody2mo ago
it's a go app, how is it also caddy?
RyanKnack
RyanKnackOP2mo ago
I run two simultaneous scripts Like go run server.go & caddy run
Brody
Brody2mo ago
why aren't those broken out into two railway services?
RyanKnack
RyanKnackOP2mo ago
I needed to store temporary files in the ephemeral disk, because I couldn't share volumes across services
Brody
Brody2mo ago
alright fair enough alright then if you don't want the go app to be publicly exposed, simply don't publicly expose it assuming this is valid, this is what you want to use
RyanKnack
RyanKnackOP2mo ago
So without adding the host it will be private? And still reachable by service A?
Brody
Brody2mo ago
correct
RyanKnack
RyanKnackOP2mo ago
Aight awesome I'll try it out later
Brody
Brody2mo ago
sounds good
RyanKnack
RyanKnackOP2mo 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?
Brody
Brody2mo ago
correct
RyanKnack
RyanKnackOP2mo 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?
Brody
Brody2mo ago
you need to use the port too, but yes
RyanKnack
RyanKnackOP2mo ago
Oh I thought http defaults to port 80 so I didn't have to :kekw:
Brody
Brody2mo ago
it does, but it's best to not listen on a privileged port
Want results from more Discord servers?
Add your server