TypeError: Failed to parse URL from api/[user]
Unanswered
bape tista posted this in #help-forum
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 ?
look like i cant parse from my api , i should make an config object or sum ?
26 Replies
Alfonsus Ardani
where is the error?
Ray
does it work if you change the url to absolute?
like
like
http://localhost:3000/api/${instance}
?bape tistaOP
no
Ray
like the faq said, you should try fetching github directly in
getServerSideProps
bape tistaOP
I wanted to get the information from an /api , and then get the information I want with getServerSideprops, understand...
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
bape tistaOP
But what will this end point be like when it goes to production?
Ray
wdym?
this is a page?
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?
Ray
that's why you should fetch
https://api.github.com/users/${username}
directly instead of self apitip is here
you should take a look
bape tistaOP
I already have 3 fetches happening, so I want to dissolve this component a little, so I thought about doing this
joulev
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
bape tistaOP
i will read now so
bape tistaOP
What is the best practice to bring this fetch to another file???
Ray
do you mean reuse the logic?
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 ...