R
Railway•15mo ago
Josso Ares

Share $PORT across services for private networking

I have two services, CMS and Web. CMS listens on :: at port $PORT. Web listens on 0.0.0.0 at port $PORT. CMS needs to be publicly accessible through the Internet (so that Admin and Content Editors can edit content) (hence why it listens at port $PORT), but also privately available through Private Networking (so that Web can make API calls to retrieve content) (hence why it listens at ::). Web needs to know ${{CMS.PORT}} so that it can call http://cms.railway.internal:$${CMS.PORT}/. It seems like this kind of service cross-referencing the $PORT variable doesn't work. Due to a limitation in CMS, I can only listen at one (interface, port) combination, so listening both at (0.0.0.0, ${PORT}) and (::, 1234) wouldn't work (if it did, Iwouldn't need to know the Railway-assigned port, right?). How can I make this work?
24 Replies
Percy
Percy•15mo ago
Project ID: 38204806-70b2-434c-972d-215f6a2beec0
Josso Ares
Josso AresOP•15mo ago
38204806-70b2-434c-972d-215f6a2beec0
Brody
Brody•15mo ago
just simply set a PORT service variable
Josso Ares
Josso AresOP•15mo ago
wait, I thought I needed to use Railway's generated PORT variable if I want to access it publicly?
Brody
Brody•15mo ago
yeah but then when you set your own PORT in the service variables that now becomes both what your app uses and what Railway uses, provided your app already does listen on PORT
Josso Ares
Josso AresOP•15mo ago
ohhhh that's pretty neat
Brody
Brody•15mo ago
indeed
Josso Ares
Josso AresOP•15mo ago
Somewhat unrelated to $PORT, but Web is a Next.js project running Node 18 and this is happening:
#12 42.91 TypeError: fetch failed
#12 42.91 at Object.fetch (node:internal/deps/undici/undici:11576:11)
#12 42.91 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
#12 42.91 cause: Error: getaddrinfo ENOTFOUND cms.railway.internal
#12 42.91 at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26)
#12 42.91 at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
#12 42.91 errno: -3008,
#12 42.91 code: 'ENOTFOUND',
#12 42.91 syscall: 'getaddrinfo',
#12 42.91 hostname: 'cms.railway.internal'
#12 42.91 }
#12 42.91 }
#12 42.91 TypeError: fetch failed
#12 42.91 at Object.fetch (node:internal/deps/undici/undici:11576:11)
#12 42.91 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
#12 42.91 cause: Error: getaddrinfo ENOTFOUND cms.railway.internal
#12 42.91 at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26)
#12 42.91 at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
#12 42.91 errno: -3008,
#12 42.91 code: 'ENOTFOUND',
#12 42.91 syscall: 'getaddrinfo',
#12 42.91 hostname: 'cms.railway.internal'
#12 42.91 }
#12 42.91 }
so it seems like the resolver Node 18 is using doesn't know about private networking
Brody
Brody•15mo ago
are you saying this worked on node 16?
Josso Ares
Josso AresOP•15mo ago
no, but I had a somewhat similar issue locally where getaddrinfo failed for localhost on Node 18 and not on Node 16 so I thought Node version might be relevant.
Brody
Brody•15mo ago
gotcha that is the correct hostname for the cms as per it's internal domain listed in its service settings?
Josso Ares
Josso AresOP•15mo ago
yup
Josso Ares
Josso AresOP•15mo ago
No description
Brody
Brody•15mo ago
what what stage of the next apps lifecycle does it make this request?
Josso Ares
Josso AresOP•15mo ago
at build time.
Brody
Brody•15mo ago
the private network is not available at build time the build gets ran on a separate build machine that isn't part of your project
Josso Ares
Josso AresOP•15mo ago
oh. that's unfortunate I guess I'll have to use public networking then
Brody
Brody•15mo ago
yeah it is, I wonder if the team has any interest in including the builder for a service in its private network
Josso Ares
Josso AresOP•15mo ago
switching from private networking at build time to public networking at deploy time is asking for trouble with Next.js data cache
Brody
Brody•15mo ago
yeah sounds tricky
Josso Ares
Josso AresOP•15mo ago
it's unfortunate because my public network is behind CloudFlare Access so I have to deal with more auth steps I think including the builder in the private network makes perfect sense especially since many web frameworks do pre-rendering at build time nowadays
Brody
Brody•15mo ago
100% agree with you and you definitely should speak up about that in #🤗|feedback
Brody
Brody•15mo ago
awesome feedback!!
Want results from more Discord servers?
Add your server