#Fetching from server component

25 messages · Page 1 of 1 (latest)

violet dust
#

provide full url

#

https://domain.com/api/servers

untold wren
#

I guess you cant use relative url for fetch in nodejs environment

violet mural
violet dust
#

and then show ss of error

#

full

violet mural
# violet dust and then show ss of error
TypeError: Failed to parse URL from /api/servers
    at Object.fetch (/Users/charlie/Documents/Development/Projects/polls.net/node_modules/next/dist/compiled/undici/index.js:1:26684)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async getServers (webpack-internal:///(sc_server)/./app/(app)/servers/page.tsx:11:17)
    at async Page (webpack-internal:///(sc_server)/./app/(app)/servers/page.tsx:19:19) {
  digest: '3770537177'
compact birch
#

It needs the full url, since the fetch happens on the server, it doesnt know what the full url is

#

Can you provide the error when using the full url? because the above error is just with /api/servers

violet mural
#

Ah I see, I didn't know, but weirdly session is null even though I'm signed in..

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
    const {name} = req.body;

    const session = await getSession({ req });

    console.log({ session })
violet dust
#

or usesession

#

you have to use Unstable_getsession maybe that name

#

idk specific

violet mural
#

ahhh the one where i need to pass authoptions?

violet dust
#

here

#

u using getsessions

#

u cant use that function on api route

violet mural
#

but same thing, null

violet dust
#

becuse i use same

violet mural
#

its null for some reason