fetching from front in private network but getting error
this is my fetch function
async function getData() {
const userCookies = cookies()
const url = process.env.INTERNAL_BACK_URL ??"http://127.0.0.1:8000/"
const res = await fetch(url+"user/info/",
{headers: { Cookie : userCookies },})
if (!res.ok) {
throw new Error('Failed to fetch data')
}
return res.json() } and for url i used this 2 pattern but both get errors pergamer_back.railway.internal/user/info [cause]: TypeError [ERR_INVALID_URL]: Invalid URL and http://pergamer_back.railway.internal/ TypeError: fetch failed at Object.fetch (node:internal/deps/undici/undici:11576:11) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { cause: Error: connect ECONNREFUSED fd12:ae40:cb28::cf:ac56:6757:80 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: 'fd12:ae40:cb28::cf:ac56:6757', port: 80
return res.json() } and for url i used this 2 pattern but both get errors pergamer_back.railway.internal/user/info [cause]: TypeError [ERR_INVALID_URL]: Invalid URL and http://pergamer_back.railway.internal/ TypeError: fetch failed at Object.fetch (node:internal/deps/undici/undici:11576:11) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { cause: Error: connect ECONNREFUSED fd12:ae40:cb28::cf:ac56:6757:80 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: 'fd12:ae40:cb28::cf:ac56:6757', port: 80
75 Replies
Project ID:
23052b53-336e-48e9-8fa0-9a094c4b4233
23052b53-336e-48e9-8fa0-9a094c4b4233
what kind of frontend app is this?
next.js
and you are making the request from the backend of next, correct?
yes for serverside fetching
works fine in local
okay cool, and what kind of app are you trying to make a request to?
Django
can you access the django app from the railway public domain?
yes
if remove fetch in serverside in front fetching works fine
are you running the django app with gunicorn?
yes
give me your current start command please
CMD python manage.py makemigrations && python manage.py migrate && gunicorn --bind 0.0.0.0:80 core.wsgi:application
change it to
and then delete your PORT service variable
and do i need set cors orgin for it if yes waht url is it ?
if you didn't need cors before you don't need it now
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11576:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: Error: connect ECONNREFUSED fd12:ae40:cb28::2e:6608:4983:80
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: 'fd12:ae40:cb28::2e:6608:4983',
port: 80
}
}
[Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] {
digest: '956933652'
}
do i need restart my front also ?
send me the deployment logs for the django service please https://bookmarklets.up.railway.app/log-downloader/
sry i could use the link u gave
couldnt*
is it enough ?
https://api.forbtc.org/user/info/
with this link u can get json response
got it
what is
INTERNAL_BACK_URL
set to?http://pergamer_back.railway.internal/
it was without http but i got bad url
but i didnt test with new setup u gave for backend
okay, show me a full screenshot of your railway project now please
using screen shot button ?
whatever method you would like as long as the screenshot shows the entire browser window
set a
PORT
variable on the django service to 8000
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11576:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: Error: connect ECONNREFUSED fd12:ae40:cb28::11:ceeb:11a2:80
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: 'fd12:ae40:cb28::11:ceeb:11a2',
port: 80
}
}
still the same
we arent done yet dont worry
also, please only use that log downloader when sending your logs
Ok 👍
change your
INTERNAL_BACK_URL
variable to http://${{pergamer_back.RAILWAY_PRIVATE_DOMAIN}}:${{pergamer_back.PORT}}
make sure to cancel the deployment popup
once done, click the eye icon and send me the resulting stringmy variable does not have a trailing slash, why does the resulting string have a trailing slash
at end ?
yes, did you add a slash at the end?
i need end slash to works
you shouldnt, please keep the variable as i have said
Ok
okay now you can go ahead and restart the next deployment, 3 dot menu on the active deployment
ok should edit my url so add slash before the end point ?
i dont see why you would need it
const url = process.env.INTERNAL_BACK_URL ??"http://127.0.0.1:8000/"
const res = await fetch(url+"user/info/",
after port
do this then
url + "/user/info/"
some thing changed but not working
well thats a different error, so that means progress
do this again for me please
that 's the spirit 👍
http://pergamer_back.railway.internal:8000
no trailing slash!
it doent have slash but when copy it aperas
http://pergamer_back.railway.internal:8000
okay show me in screenshot please
cool, show me the new fetch code then please, and enclose the code in triple back ticks please
async function getData() {
const userCookies = cookies()
const url = process.env.INTERNAL_BACK_URL ??"http://127.0.0.1:8000"
const res = await fetch(url+"/user/info/",
{headers: { Cookie : userCookies },})
if (!res.ok) {
throw new Error('Failed to fetch data')
}
return res.json() }
return res.json() }
okay then make next give us a better error printout
also, you can still access the django service from the public domain right?
yes
let me know when you have made next give a better error printout
i dont get this
Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details.
make next give us the actually errorthat the actual error (this part shows in browser) but the logs i sent is actual record
as the error message states, it is most certainly not the actual error
if you check logs it has ending that adres to the browser error the last part of it
there is no useful information here, as ive said, make next give us the actual error
for example
in browser :
Application error: a server-side exception has occurred (see the server logs for more information).
Digest: 2964946319
in server log
Error: Failed to fetch data
at getData (/app/.next/server/chunks/145.js:1:11775)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async User (/app/.next/server/chunks/145.js:1:11846)
[Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] {
digest: '2964946319'
}
it's joint so you adress the error to find real log in seerver
let me know when you are able to configure next to print the actual error
it's actual error im sure about it
there is no useful information here, as ive said, make next give us the actual error
without an actual error, i cant help
Ok i dont know how but i will try tommorw if get new kind of error ty for help anyway really patient man/women
no problem (man) 🤣
django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'pergamer_back.railway.internal:8000'. The domain name provided is not valid according to RFC 1034/1035.
oh now django dont accept it
time for you to read the django docs 🙂
actualy after error changed now next can connect but django doesnt accept to call by that
URL
^
Fixed
railway use the default github name for the internal url but django doesnt accept the any character in the url so i needed the change the internal url to fix last part
awesome!