Next.js Discord

Discord Forum

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

Unanswered
bape tista posted this in #help-forum
Open in Discord
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 ?

26 Replies

@bape tista 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 ?
does it work if you change the url to absolute?
like http://localhost:3000/api/${instance}?
@bape tista no
like the faq said, you should try fetching github directly in getServerSideProps
I wanted to get the information from an /api , and then get the information I want with getServerSideprops, understand...
@bape tista I wanted to get the information from an /api , and then get the information I want with getServerSideprops, understand...
why don't you just change /api/${username} to https://api.github.com/users/${username}?
@Ray does it work if you change the url to absolute? like `http://localhost:3000/api/${instance}`?
like I said, you need to use absolute url in getServerSideprops
@Ray why don't you just change `/api/${username}` to `https://api.github.com/users/${username}`?
But what will this end point be like when it goes to production?
this is a page?
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?
@bape tista Click to see attachment
Is doing what I'm doing a good practice? Do you want to give me a tip?
@bape tista When the domain is no longer localhost 3000, when I deploy, my domain will change, do I not need to configure this?
that's why you should fetch https://api.github.com/users/${username} directly instead of self api
you should take a look
I already have 3 fetches happening, so I want to dissolve this component a little, so I thought about doing this
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
i will read now so
What is the best practice to bring this fetch to another file???
@Ray do you mean reuse the logic?
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 ...