R
Railwayā€¢13mo ago
macwilko

Axios (node server) private network

If my private network name is "exotic-auth", how can I do a Axios request to it via private network. The http client is setup like this:
const authApi = axios.create({
baseURL: process.env.API_URL,
timeout: 15_000,
headers: standardHeaders
});
const authApi = axios.create({
baseURL: process.env.API_URL,
timeout: 15_000,
headers: standardHeaders
});
for API_URL I've tried http://exotic-auth/v1 and exotic-auth/v1 but nether resolve.
Solution:
fiber runs on tcp4 by default, and the private network is ipv6 only, so tcp tells fiber to bind to both tcp4 and tcp6 (ipv4, ipv6)
Jump to solution
36 Replies
Percy
Percyā€¢13mo ago
Project ID: dd3f96f7-3ab3-4453-86a3-32328b2f81d6
macwilko
macwilkoOPā€¢13mo ago
dd3f96f7-3ab3-4453-86a3-32328b2f81d6
Brody
Brodyā€¢13mo ago
what port does it listen on?
macwilko
macwilkoOPā€¢13mo ago
i guess whichever $PORT is set by railway right? but it's a web server via REST its accessible on its public URL over https://
Brody
Brodyā€¢13mo ago
you can think of the private network like a lan, if you wanted to access an http service on another device on the lan, you would need to use a port in your url in that scenario, this is the same for railway private network, you need to use a port when connecting to other services in the private network
macwilko
macwilkoOPā€¢13mo ago
i see i see so I should specify the port in the uri
Brody
Brodyā€¢13mo ago
indeed
macwilko
macwilkoOPā€¢13mo ago
ok big brain question here, can I use port 80 ? šŸ˜„ im guessing not, it's probably assigned a random port right
Brody
Brodyā€¢13mo ago
I can't recommend you listen on a privileged port if it is indeed listening on railways random PORT, simply set a fixed PORT service variable and use that same port when making requests to the service across the private network
macwilko
macwilkoOPā€¢13mo ago
booom! right that'll solve it lemme do that ok weirdly baseURL: 'exotic-auth:3000/v1', AxiosError: Unsupported protocol exotic-auth: i'm guessing i need to use http://exotic-auth:3000/v 1
Brody
Brodyā€¢13mo ago
yes use http, and use the full domain name instead for good measure
macwilko
macwilkoOPā€¢13mo ago
right oof if this works gonna be so good i imagine even faster
Brody
Brodyā€¢13mo ago
and zero networking costs as long as communication is done exclusively over the private network
macwilko
macwilkoOPā€¢13mo ago
yeah mostly doing this because damn Cloudflare is acting up though reliability + speed
Brody
Brodyā€¢13mo ago
lmao you'll have that when an entire core data center drops offline
macwilko
macwilkoOPā€¢13mo ago
nooooo getting AxiosError: connect ECONNREFUSED fd12:34a7:645b::a3:de4:3b2a:3000 on
baseURL: 'http://exotic-auth:3000/v1';,
method: 'post',
url: '/auth/sign_in',
baseURL: 'http://exotic-auth:3000/v1';,
method: 'post',
url: '/auth/sign_in',
Going to try the full internal name exotic-auth.railway.internal
Brody
Brodyā€¢13mo ago
are you sure your exotic thingy is running on port 3000?
macwilko
macwilkoOPā€¢13mo ago
http://exotic-auth.railway.internal:3000/v1 yes one sec
time=2023-11-04T16:27:31.083Z level=INFO msg="šŸš€ Starting auth api āœ…"

time=2023-11-04T16:27:36.097Z level=INFO msg=Connected

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”

ā”‚ Fiber v2.50.0 ā”‚

ā”‚ http://127.0.0.1:3000 ā”‚

ā”‚ (bound on host 0.0.0.0 and port 3000) ā”‚

ā”‚ ā”‚

ā”‚ Handlers ............ 33 Processes ........... 1 ā”‚

ā”‚ Prefork ....... Disabled PID ................. 1 ā”‚

ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
time=2023-11-04T16:27:31.083Z level=INFO msg="šŸš€ Starting auth api āœ…"

time=2023-11-04T16:27:36.097Z level=INFO msg=Connected

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”

ā”‚ Fiber v2.50.0 ā”‚

ā”‚ http://127.0.0.1:3000 ā”‚

ā”‚ (bound on host 0.0.0.0 and port 3000) ā”‚

ā”‚ ā”‚

ā”‚ Handlers ............ 33 Processes ........... 1 ā”‚

ā”‚ Prefork ....... Disabled PID ................. 1 ā”‚

ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
Brody
Brodyā€¢13mo ago
ah I see the problem, let me consult the fiber docs
macwilko
macwilkoOPā€¢13mo ago
oh
Brody
Brodyā€¢13mo ago
in fiber.Config set Network to tcp
macwilko
macwilkoOPā€¢13mo ago
right
Solution
Brody
Brodyā€¢13mo ago
fiber runs on tcp4 by default, and the private network is ipv6 only, so tcp tells fiber to bind to both tcp4 and tcp6 (ipv4, ipv6)
macwilko
macwilkoOPā€¢13mo ago
O.O i have no idea how you work that out brody salute ^.^
Brody
Brodyā€¢13mo ago
I read the fiber docs so I know about this specific thing, I just had to check back for the correct config name
macwilko
macwilkoOPā€¢13mo ago
yeah šŸ™‚ works. damn pretty cool
Brody
Brodyā€¢13mo ago
pog
macwilko
macwilkoOPā€¢13mo ago
fr this must also add some speed... i think pretty much everything is communicating by private network now
Brody
Brodyā€¢13mo ago
doesn't need to loopback around on the edge, yeah
macwilko
macwilkoOPā€¢13mo ago
side question but do you think railway webhooks can also resolve on the private network lol i'm gonna test it but this would be nice, since then I can verify the webhook came from railway also
Brody
Brodyā€¢13mo ago
nope it can't
macwilko
macwilkoOPā€¢13mo ago
ahh fair.
Brody
Brodyā€¢13mo ago
you could verify by cidr range maybe
macwilko
macwilkoOPā€¢13mo ago
i might add that as feedback, usually webhooks contain a HMAC or some means to verify the sender but since it's railway, i figured a private network thingy might do it also or some special header
Brody
Brodyā€¢13mo ago
see what headers they do set, maybe there will be something useful
macwilko
macwilkoOPā€¢13mo ago
true!
Want results from more Discord servers?
Add your server