Next.js Discord

Discord Forum

Deploying App and using fetch('localhost') for local api routes

Unanswered
thatdoritoguy posted this in #help-forum
Open in Discord
I have trouble deploying my app to vercel after migrating to next 13. The current/new version uses fetch() and localhost to get data from my local api routes. As only absolute routes are accepted i don't how to change it so that i can deploy from my domain. Before i didnt have this problem since i used getserverside props but now i'm unsure to what to change my url fetch link as to get data from my local api and deploy without error. Essentially i'm met with TypeError: fetch failed . I'm aware this is probably a common error but i could not find a relevant solution both in the docs or in the previous posts in this forum. Also I would like my fetch request to work both in local testing and on deployment

2 Replies

you shouldn't fetch your own API routes in the server, you can run the code directly in the place of the fetch call. https://nextjs-discord-common-questions.joulev.dev/fetching-own-api-endpoint-in-react-server-components
okay thanks , didnt really see that and the course i watched did exactly the opposite , which kinda sucks. But if that works then i shouldnt have a problem. Thanks