Issue regarding connecting Directus and Next.js with internal routing
Anonymous
TRIALOP

2 years ago

I am trying to connect my next.js app with Directus using internal routing. Both of them are within the same project.

I keep getting this error:
```cause: Error: getaddrinfo ENOTFOUND directus.railway.internal

12 50.12 at GetAddrInfoReqWrap.onlookup as oncomplete

12 50.12 at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {

12 50.12 errno: -3008,

12 50.12 code: 'ENOTFOUND',

12 50.12 syscall: 'getaddrinfo',

12 50.12 hostname: 'directus.railway.internal'

12 50.12 },

12 50.12 digest: '2095498725'

12 50.12 }```

This is the variable I am using for the route: DIRECTUS_HOST_URL=http://${{directus.RAILWAY_PRIVATE_DOMAIN}}:${{directus.PORT}}

I believe it is due to setting up Ipv6 on the directus instance. I changed the host to :: , but that does not change anything, and neither does ::0.0.0.0.

0 Replies

Anonymous
TRIALOP

2 years ago

N/A


medim
MODERATOR

2 years ago

So, what happens in my template is that Directus <-> DB uses private networking


medim
MODERATOR

2 years ago

In your case you are trying to do NextJs <-> Directus


medim
MODERATOR

2 years ago

And Directus is basically your API so it can't be in the private networking


Anonymous
TRIALOP

2 years ago

Why cannot it be in the private network?
Thank you a lot for helping out btw


medim
MODERATOR

2 years ago

Unless you are doing NextJs <-> API <-> Directus, this way you can make the connection between your API and Directus private


medim
MODERATOR

2 years ago

'cause how would your user be able to access it?


medim
MODERATOR

2 years ago

your user doesn't and cant access your services in the private network


Anonymous
TRIALOP

2 years ago

So, my next.js will fetch the data with server functions, and then display it on the client. The user would just access the next.js site, perhaps I completely misunderstand how this is supposed to be working. But my understanding is that I would connect the next.js app with directus using nexjs server features. Wouldn't that work like connecting a backend to directus?


medim
MODERATOR

2 years ago

So now u just hit a grey area <:kekw:788259314607325204>
I thought about that, but I don't know how it works, I don't use NextJs or its server features


medim
MODERATOR

2 years ago

That would be a good question to make on the Nextjs discord server


Anonymous
TRIALOP

2 years ago

I most probably will ask there as well. Thank you for taking the time to help me out.


medim
MODERATOR

2 years ago

Np, sorry that I couldn't really help you


Anonymous
TRIALOP

2 years ago

No problem of course :))


brody
EMPLOYEE

2 years ago

these two docs sections may provide more information


Anonymous
TRIALOP

2 years ago

Thank you, I did already look into this although this confuses me a bit:

"A web application that makes client-side requests cannot communicate to another service over the private network."

Does this mean internal routing would not work with next.js?


Anonymous
TRIALOP

2 years ago

The faq answers this, just saw that one so thank you again.
But still does not solve my issue, I think it might have something to do with ipV6 with directus, I tried different solutions but none seem to be working


brody
EMPLOYEE

2 years ago

so you are
making the requests to directus from the server side of your nextjs app?
and
the nextjs app is in the same project?


Anonymous
TRIALOP

2 years ago

yes, the next.js and directus are within the same project, and I am using server side to make directus requests.


brody
EMPLOYEE

2 years ago

what errors are you getting


Anonymous
TRIALOP

2 years ago

```cause: Error: getaddrinfo ENOTFOUND directus.railway.internal

12 50.12 at GetAddrInfoReqWrap.onlookup as oncomplete

12 50.12 at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {

12 50.12 errno: -3008,

12 50.12 code: 'ENOTFOUND',

12 50.12 syscall: 'getaddrinfo',

12 50.12 hostname: 'directus.railway.internal'

12 50.12 },

12 50.12 digest: '2095498725'

12 50.12 }

12 50.12

12 50.12 Error occurred prerendering page "/articles". Read more: https://nextjs.org/docs/messages/prerender-error

12 50.12

12 50.12 TypeError: fetch failed

12 50.12 at Object.fetch (node:internal/deps/undici/undici:11372:11)

12 50.12 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

12 50.12 at async Object.request (/app/.next/server/chunks/330.js:15:33663)

12 50.12 at async l (/app/.next/server/app/articles/page.js:1:2892)

12 50.14

12 50.14 > Export encountered errors on following paths:

12 50.14 /articles/page: /articles

```


brody
EMPLOYEE

2 years ago

can you show me a screenshot of your railway project?


Anonymous
TRIALOP

2 years ago

Do you mean like this?

1233100853179580400


brody
EMPLOYEE

2 years ago

did you deploy directus yourself?


Anonymous
TRIALOP

2 years ago

yes,
{ "name": "directus", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "npx directus start" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "directus": "^10.10.5", "pg": "^8.11.5" } }
this is the package.json for it,


brody
EMPLOYEE

2 years ago

thats very far from ideal


brody
EMPLOYEE

2 years ago

please scap that and deploy medim's directus template


Anonymous
TRIALOP

2 years ago

https://supabase.com/partners/integrations/directus
I used this to set up directus with supabase, could you tell me what is not ideal about it? Thank you a lot for taking the time to help me out btw


brody
EMPLOYEE

2 years ago

your directus deploys from github instead of an image, doesnt have persistent storage, doesnt dual stack bind, doesnt have a health check, is likely missing some env vars, etc etc


Anonymous
TRIALOP

2 years ago

ok, thank you very much! I will look into the template you mentioned. I followed the tutorial to set it up with Supabase as the storage. Perhaps, I can do that with the tempalte as well.


brody
EMPLOYEE

2 years ago

yep you can customize the service after you deploy the template, its just better to start off with the template that is designed to run on railway in a production setting than it is to deploy it yourself


brody
EMPLOYEE

2 years ago

though i dont know if i can recommend using supabase for the database or storage, you would be subjecting yourself to egress fees from railway


brody
EMPLOYEE

2 years ago

and even if you didn't care about egress fees, there's still that extra round trip time from contacting external services


Anonymous
TRIALOP

2 years ago

Great, that sounds quite good


Anonymous
TRIALOP

2 years ago

keeping supabase as the database is a bit of a necessity, otherwise in case of no constraints it does make sense to keep the database within railway


brody
EMPLOYEE

2 years ago

may I ask why it's a necessity to use supabase?


Anonymous
TRIALOP

2 years ago

It wasn't really my decision to do it like that, so I can't answer it properly. But one reason was that we are using supabase for other data, and we need to share it across apps although not all apps use directus.


brody
EMPLOYEE

2 years ago

gotcha


brody
EMPLOYEE

2 years ago

okay let me know when you have medim's template deployed into your project and configured to your liking, then we can pick this back up!


Anonymous
TRIALOP

2 years ago

Wonderful, I will definitely let you know even if all goes well.


brody
EMPLOYEE

2 years ago

now keep in mind when you go to deploy the template into your project, you will see multiple duplicates, make sure you only deploy the one with medim's name on it, it is the only template we would be able to provide support for and we are in the process of removing all other duplicates


Loading...