Next.js Discord

Discord Forum

http://localhost:3000/api route in deploy problem

Unanswered
Somali posted this in #help-forum
Open in Discord
Avatar
SomaliOP
I am new to NextJs, I'm making a fullstack project with nextjs, in my local machine my code is running at http://localhost:3000/ and my api appears at http://localhost:3000/api/all-news, and i fetch all of my data from here, the problem is when i want to deploy this project somewhere , it might be vercel, what I should give as my api route name, as the vercel couldn't recognize localhost servers.

please help me with the solution of the problem!
Thanks in Advance!

5 Replies

Avatar
European sprat
/api/all-news
Avatar
SomaliOP
It's give a "Error: Failed to parse URL from /api/all-news" when I try to fetch data at a server component!
Avatar
European sprat
you shouldn't be consuming your own route handlers in server components. just access the data directly
but if you absolutely must do it then i think you need the full URL http://localhost:3000/api/all-news i don't know how it works with vercel but i have different environment variables for the "BASE_URL" which fills that in depending on my environment
but really try to avoid fetching your own routes from server components...