Bind Express App to IPv6?
I deployed my Express API to Railway and its talking to Redis and Postgres nicely. My client is built in Next 13 with the App Router and is having trouble discovering
I think this has to do with my binding the Express app to an IPv6 port or at least making it accessible through IPv6 however after a few hours of searching I'm unable to find a clear way of doing this?
client <> server is communicating through ApolloServer.
This is my app.js in my server root. Thanks for any insights.
Solution:Jump to solution
you'd have to use the public address during build and then have your app switch to the private address during runtime
33 Replies
Project ID:
N/A
N/A
I must be blind, what is
NODE_PORT
set to?8080
Not blind. I left the import statements out
okay and what error do you get when calling that host:port you gave at the top of your message?
It errors during build.
Dockerfile
Error - image
ah, the private network is not available during build
Solution
you'd have to use the public address during build and then have your app switch to the private address during runtime
Interesting. Okay I'll give that a shot.
Thanks very much.
I'm thinking of doing that address switch using start scripts. Would something like this be a good idea?
you'd want to use actual environment variables, but yeah I can see that working
Got it. Thank you. I'll see how I might use env vars.
in your service variables add two new variables
set them accordingly with reference variables https://docs.railway.app/develop/variables#railway-provided-variables
specifically using
and
then in your scripts you either do
or
tell me the service name of the backend and I'll write the reference variables for you
Mind if I give it a shot first? It'll help me learn faster.
absolutely, love that attitude
Oddly, Next is having trouble pulling in env vars from the service on Railway. I'm triaging that now.
Vars that appear in next.config.js work but calling process.env.[var] doesn't detect any service vars.
Variables look OK. I am curious as to what Railway "pre-pends" the URLs with. My web socket services starts with "ws://.." and I want to make sure I account for that
you prefix the reference variables yourself
Perfect
so lets see your reference variables
this is your dockerfile for your next app right?
whoops
thats old
show me the raw values for these?
that referances the same services private and public domain, i thought you wanted to reference a different services public and private domains?
I probably did a bad job of explaining.
I have an API built with Express that I want my client (Next) to access.
API_PRIVATE_URL and API_PUBLIC_URL above are to connect to the express app from the Next app.
Next vars:
Next var raw
oh okay then you did do it right, you where missing the second screenshot for added context
well besides the missing scheme at least its right
do this on the next vars
ah.. add the http:// before the ${{....}} ref?
yep, railway will do the string interpolation
thats neat, let me give it a shot
youll need to use this dockerfile too
Just updated it, thanks.
hey just wanting to check back in, did you get this working how you wanted?
Yes, this is answered! Thanks Brody.