TypeError: Failed to parse URL from api/[user]
Unanswered
bape tista posted this in #help-forum
![Avatar](https://cdn.discordapp.com/avatars/543642083408347168/8e59cdd428ad34e0304ca76e7ee8deb6.webp?size=256)
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 ?
![Image](https://cdn.discordapp.com/attachments/1192232473472540823/1192232473694830712/image.png?ex=65a85404&is=6595df04&hm=6497c4755d3da8322072f155fbf174ea03128ff8d53c088b7f536606a811b888&)
26 Replies
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/708a8637ada505b6b7a85972807d9dca.webp?size=256)
Alfonsus Ardani
where is the error?
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
does it work if you change the url to absolute?
like
like
http://localhost:3000/api/${instance}
?![Avatar](https://cdn.discordapp.com/avatars/543642083408347168/8e59cdd428ad34e0304ca76e7ee8deb6.webp?size=256)
bape tistaOP
no
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
like the faq said, you should try fetching github directly in
getServerSideProps
![Avatar](https://cdn.discordapp.com/avatars/543642083408347168/8e59cdd428ad34e0304ca76e7ee8deb6.webp?size=256)
bape tistaOP
![Image](https://cdn.discordapp.com/attachments/1192232473472540823/1192372457982673017/image.png?ex=65a8d663&is=65966163&hm=4b438c8b4e35bbebc0f54ef1763c0e07f5d0f43ebe5c341b2f6c9a6cd9edafef&)
I wanted to get the information from an /api , and then get the information I want with getServerSideprops, understand...
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
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](https://cdn.discordapp.com/avatars/543642083408347168/8e59cdd428ad34e0304ca76e7ee8deb6.webp?size=256)
bape tistaOP
But what will this end point be like when it goes to production?
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
wdym?
this is a page?
![Avatar](https://cdn.discordapp.com/avatars/543642083408347168/8e59cdd428ad34e0304ca76e7ee8deb6.webp?size=256)
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](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
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
![Avatar](https://cdn.discordapp.com/avatars/543642083408347168/8e59cdd428ad34e0304ca76e7ee8deb6.webp?size=256)
bape tistaOP
I already have 3 fetches happening, so I want to dissolve this component a little, so I thought about doing this
![Image](https://cdn.discordapp.com/attachments/1192232473472540823/1192374421181181962/image.png?ex=65a8d837&is=65966337&hm=17fdc7c32f05c0ff04255e5132db9f88ef6a5454d85567167b7c77b53345d9c0&)
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/44415017de6fed2ccd5d44b4b2051ac0.webp?size=256)
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
![Avatar](https://cdn.discordapp.com/avatars/543642083408347168/8e59cdd428ad34e0304ca76e7ee8deb6.webp?size=256)
bape tistaOP
i will read now so
![Avatar](https://cdn.discordapp.com/avatars/543642083408347168/8e59cdd428ad34e0304ca76e7ee8deb6.webp?size=256)
bape tistaOP
What is the best practice to bring this fetch to another file???
![Image](https://cdn.discordapp.com/attachments/1192232473472540823/1192379941531156480/image.png?ex=65a8dd5b&is=6596685b&hm=073197602753fe6f4325366d0f1a3408529239b0d0feb77d02ebed93c328123e&)
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
do you mean reuse the logic?
![Avatar](https://cdn.discordapp.com/avatars/543642083408347168/8e59cdd428ad34e0304ca76e7ee8deb6.webp?size=256)
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 ...