Nextjs and node server not able to communicate over private networking
bertvereecken
TRIALOP

a year ago

Hi,

Context:
I have a monorepo with turborepo with two apps inside:

  • web (nextjs)

  • backend (node server)

I would like these two to communicate with each other over the private network.

I've read the docs and previous threads, but I am still not able to get it working.

My node server is listening on :: (to allowd IPv6) on port 3001.

In my web package I am fetching the following endpoint;

const baseUrl = env.NEXT_PUBLIC_BACKEND_BASE_URL;

const bookAxiosClient = axios.create({
  baseURL: `${baseUrl}/books`,
});

In my web service in Railway I've set the following env var:
NEXTPUBLICBACKENDBASEURL=http://${{Turbo repo BE.RAILWAYPRIVATEDOMAIN}}:3001/api

When i check the deployed frontend I see these errors (see attached screenshots)

Hopefully somebody can help me 🙂

Bert

Solved

31 Replies

bertvereecken
TRIALOP

a year ago

4838d5a0-e5bd-482c-bbf8-35740edea841


brody
EMPLOYEE

a year ago

if the user's browser is making the api call (it is) then you need to use the public domain, it would not be a very private network if anyones browser could make a fetch call to a domain on the private network


bertvereecken
TRIALOP

a year ago

Thanks for the swift reply 🙂


bertvereecken
TRIALOP

a year ago

Makes sense. Networking noob here 😦 Will try that and couple back to you.


brody
EMPLOYEE

a year ago

sounds good!


bertvereecken
TRIALOP

a year ago

Mmm, still no success.

So what i did:

  • Changed the env var to the public name like this:
    ${{Turbo repo BE.RAILWAY_PUBLIC_DOMAIN}}/api


bertvereecken
TRIALOP

a year ago

Now i receive a 404 error.


bertvereecken
TRIALOP

a year ago

1317405974155235300


brody
EMPLOYEE

a year ago

you're calling the frontend domain


brody
EMPLOYEE

a year ago

I see fe there


bertvereecken
TRIALOP

a year ago

Huh, how is that possible: i changed my env var to this ?

${{Turbo repo BE.RAILWAYPUBLICDOMAIN}}/api


bertvereecken
TRIALOP

a year ago

1317406224039415800


brody
EMPLOYEE

a year ago

then you have to use that in code


bertvereecken
TRIALOP

a year ago

1317406375458115600


brody
EMPLOYEE

a year ago

console logging time


bertvereecken
TRIALOP

a year ago

https://turbo-repo-fe-production.up.railway.app/turborepo-production.up.railway.app/api/books
Seems like nextjs is interfering ? This is a 404 page of next itself.


brody
EMPLOYEE

a year ago

oh


brody
EMPLOYEE

a year ago

you forgot to add https:// to the variable in Railway


bertvereecken
TRIALOP

a year ago

Ok, will try that. Thought it was already included in that variable.


bertvereecken
TRIALOP

a year ago

1317407850774925300


brody
EMPLOYEE

a year ago

nope, domain is a domain, not url


brody
EMPLOYEE

a year ago

also, it's better practice to not put /api there, do that in code


bertvereecken
TRIALOP

a year ago

Ok, will also do that 🙂


bertvereecken
TRIALOP

a year ago

You are a hero ! Thanks @Brody

1317408420596289500


brody
EMPLOYEE

a year ago

no problem!


bertvereecken
TRIALOP

a year ago

Must say this is 10/10 support. Even answering on a saturday 🙂 Thanks


brody
EMPLOYEE

a year ago

haha thank you


bertvereecken
TRIALOP

a year ago

Just a follow up question: in my backend do i still need to bind it to :: now that I am using a public url ? I suppose this can be gone now ?


brody
EMPLOYEE

a year ago

you dont need to, but it doesn't hurt


bertvereecken
TRIALOP

a year ago

Ok thanks 🙂


brody
EMPLOYEE

a year ago

!s


Status changed to Solved brody • about 1 year ago


Loading...