R
Railway2mo ago
Fouzan

Issue regarding connecting Directus and Next.js with internal routing

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] (node:dns:108:26)

#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 }
cause: Error: getaddrinfo ENOTFOUND directus.railway.internal

#12 50.12 at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26)

#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}}
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.
31 Replies
Percy
Percy2mo ago
Project ID: N/A
Fouzan
Fouzan2mo ago
N/A
Medim
Medim2mo ago
So, what happens in my template is that Directus <-> DB uses private networking In your case you are trying to do NextJs <-> Directus And Directus is basically your API so it can't be in the private networking
Fouzan
Fouzan2mo ago
Why cannot it be in the private network? Thank you a lot for helping out btw
Medim
Medim2mo ago
Unless you are doing NextJs <-> API <-> Directus, this way you can make the connection between your API and Directus private 'cause how would your user be able to access it? your user doesn't and cant access your services in the private network
Fouzan
Fouzan2mo 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
Medim2mo ago
So now u just hit a grey area :kekw: I thought about that, but I don't know how it works, I don't use NextJs or its server features That would be a good question to make on the Nextjs discord server
Fouzan
Fouzan2mo ago
I most probably will ask there as well. Thank you for taking the time to help me out.
Medim
Medim2mo ago
Np, sorry that I couldn't really help you
Fouzan
Fouzan2mo ago
No problem of course :))
Fouzan
Fouzan2mo 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? 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
Brody2mo 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?
Fouzan
Fouzan2mo ago
yes, the next.js and directus are within the same project, and I am using server side to make directus requests.
Brody
Brody2mo ago
what errors are you getting
Fouzan
Fouzan2mo ago
cause: Error: getaddrinfo ENOTFOUND directus.railway.internal
#12 50.12 at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26)
#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

cause: Error: getaddrinfo ENOTFOUND directus.railway.internal
#12 50.12 at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26)
#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
Brody2mo ago
can you show me a screenshot of your railway project?
Fouzan
Fouzan2mo ago
Do you mean like this?
No description
Brody
Brody2mo ago
did you deploy directus yourself?
Fouzan
Fouzan2mo 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"
}
}
{
"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
Brody2mo ago
thats very far from ideal please scap that and deploy medim's directus template
Fouzan
Fouzan2mo 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
Supabase
Directus | Works With Supabase
Power any project with a modern, open source data platform.
Brody
Brody2mo 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
Fouzan
Fouzan2mo 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
Brody2mo 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 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 and even if you didn't care about egress fees, there's still that extra round trip time from contacting external services
Fouzan
Fouzan2mo ago
Great, that sounds quite good 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
Brody2mo ago
may I ask why it's a necessity to use supabase?
Fouzan
Fouzan2mo 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
Brody2mo ago
gotcha 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!
Fouzan
Fouzan2mo ago
Wonderful, I will definitely let you know even if all goes well.
Brody
Brody2mo 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