Next.js Discord

Discord Forum

Why is fetching from external API working in dev mode but not on prod?

Answered
American Fuzzy Lop posted this in #help-forum
Open in Discord
American Fuzzy LopOP
https://github.com/gcerame/discogs-digger-frontend/ this is the URL of the repo, I have a fetch function inside /src/service.js that is called from useEffect inside /pages/index.js. The call is made to an external api I have in node/express. when running next dev, the fetching works, but when I build and run it, it appends my external API url to the next app URL (http://localhost:3000/localhost:3001/search/?style=house). Any ideas why this is happening? pretty new to next and struggling to find info about this
Answered by Rafael Almeida
make sure your API_URL environment variable is an absolute URL (e.g. it includes the protocol) otherwise the browser will append it to the current URL
View full answer

2 Replies

make sure your API_URL environment variable is an absolute URL (e.g. it includes the protocol) otherwise the browser will append it to the current URL
Answer
American Fuzzy LopOP
@Rafael Almeida gracias!! that seemed to be the problem!