#fetching from front in private network but getting error

91 messages · Page 1 of 1 (latest)

ripe hare
#

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

umbral impBOT
#

Project ID: 23052b53-336e-48e9-8fa0-9a094c4b4233

ripe hare
#

23052b53-336e-48e9-8fa0-9a094c4b4233

hallow mantle
#

what kind of frontend app is this?

ripe hare
#

next.js

hallow mantle
#

and you are making the request from the backend of next, correct?

ripe hare
#

yes for serverside fetching

#

works fine in local

hallow mantle
#

okay cool, and what kind of app are you trying to make a request to?

ripe hare
#

Django

hallow mantle
#

can you access the django app from the railway public domain?

ripe hare
#

yes

#

if remove fetch in serverside in front fetching works fine

hallow mantle
#

are you running the django app with gunicorn?

ripe hare
#

yes

hallow mantle
#

give me your current start command please

ripe hare
#

CMD python manage.py makemigrations && python manage.py migrate && gunicorn --bind 0.0.0.0:80 core.wsgi:application

hallow mantle
#

change it to

 python manage.py makemigrations && python manage.py migrate && gunicorn -b [::]:$PORT core.wsgi:application

and then delete your PORT service variable

ripe hare
#

and do i need set cors orgin for it if yes waht url is it ?

hallow mantle
#

if you didn't need cors before you don't need it now

ripe hare
#

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 ?

hallow mantle
ripe hare
#

sry i could use the link u gave

#

couldnt*

#

is it enough ?

hallow mantle
#

what is INTERNAL_BACK_URL set to?

ripe hare
#

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

hallow mantle
#

okay, show me a full screenshot of your railway project now please

ripe hare
#

using screen shot button ?

hallow mantle
#

whatever method you would like as long as the screenshot shows the entire browser window

ripe hare
hallow mantle
#

set a PORT variable on the django service to 8000

ripe hare
#

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

hallow mantle
#

we arent done yet dont worry

#

also, please only use that log downloader when sending your logs

ripe hare
#

Ok 👍

hallow mantle
#

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 string

ripe hare
#

http://pergamer_back.railway.internal:8000

hallow mantle
#

my variable does not have a trailing slash, why does the resulting string have a trailing slash

ripe hare
#

at end ?

hallow mantle
#

yes, did you add a slash at the end?

ripe hare
#

i need end slash to works

hallow mantle
#

you shouldnt, please keep the variable as i have said

ripe hare
#

Ok

hallow mantle
#

okay now you can go ahead and restart the next deployment, 3 dot menu on the active deployment

ripe hare
#

ok should edit my url so add slash before the end point ?

hallow mantle
#

i dont see why you would need it

ripe hare
#

after port

hallow mantle
#

do this then url + "/user/info/"

ripe hare
#

some thing changed but not working

hallow mantle
#

well thats a different error, so that means progress

hallow mantle
ripe hare
#

that 's the spirit 👍

#

http://pergamer_back.railway.internal:8000

hallow mantle
#

no trailing slash!

ripe hare
#

it doent have slash but when copy it aperas

#

http://pergamer_back.railway.internal:8000

hallow mantle
#

okay show me in screenshot please

ripe hare
hallow mantle
#

cool, show me the new fetch code then please, and enclose the code in triple back ticks please

ripe hare
#

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()
}

hallow mantle
#

okay then make next give us a better error printout

#

also, you can still access the django service from the public domain right?

hallow mantle
ripe hare
hallow mantle
#

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 error

ripe hare
#

that the actual error (this part shows in browser) but the logs i sent is actual record

hallow mantle
#

as the error message states, it is most certainly not the actual error

ripe hare
#

if you check logs it has ending that adres to the browser error the last part of it

hallow mantle
# ripe hare

there is no useful information here, as ive said, make next give us the actual error

ripe hare
#

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

hallow mantle
#

let me know when you are able to configure next to print the actual error

ripe hare
#

it's actual error im sure about it

hallow mantle
# ripe hare

there is no useful information here, as ive said, make next give us the actual error

#

without an actual error, i cant help

ripe hare
#

Ok i dont know how but i will try tommorw if get new kind of error ty for help anyway really patient man/women

hallow mantle
#

no problem (man) 🤣

ripe hare
#

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

hallow mantle
#

time for you to read the django docs 🙂

ripe hare
#

actualy after error changed now next can connect but django doesnt accept to call by that
URL

hallow mantle
ripe hare
#

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