Next.js Discord

Discord Forum

TypeError: Failed to parse URL from api/[user]

Unanswered
bape tista posted this in #help-forum
Open in Discord
Avatar
bape tistaOP
I'm having an error with this code block

look like i cant parse from my api , i should make an config object or sum ?
Image

26 Replies

Avatar
Alfonsus Ardani
where is the error?
Avatar
Ray
does it work if you change the url to absolute?
like http://localhost:3000/api/${instance}?
Avatar
joulev & fuma pray for Schneider
Avatar
bape tistaOP
no
Avatar
Ray
like the faq said, you should try fetching github directly in getServerSideProps
Avatar
bape tistaOP
Image
I wanted to get the information from an /api , and then get the information I want with getServerSideprops, understand...
Avatar
Ray
why don't you just change /api/${username} to https://api.github.com/users/${username}?
like I said, you need to use absolute url in getServerSideprops
Avatar
bape tistaOP
But what will this end point be like when it goes to production?
Avatar
Ray
wdym?
this is a page?
Avatar
bape tistaOP
ok , it worked
but
When the domain is no longer localhost 3000, when I deploy, my domain will change, do I not need to configure this?
Is doing what I'm doing a good practice? Do you want to give me a tip?
Avatar
Ray
that's why you should fetch https://api.github.com/users/${username} directly instead of self api
tip is here
you should take a look
Avatar
bape tistaOP
I already have 3 fetches happening, so I want to dissolve this component a little, so I thought about doing this
Image
Avatar
joulev & fuma pray for Schneider
seems you did not take a look. please, go read the article, it's not that long
there's a reason it's there. it's one of the most common nextjs mistakes in this server
Avatar
bape tistaOP
i will read now so
Avatar
bape tistaOP
What is the best practice to bring this fetch to another file???
Image
Avatar
Ray
do you mean reuse the logic?
Avatar
bape tistaOP
yes, bring this fetch from an import function, but because nextjs is opinionated and I haven't found something in the documentation, I haven't done it yet, I want to look for an asynchronous function that executes the fetch from another file, but I'm looking for the best practice for this ...