Next.js Discord

Discord Forum

API endpoints broken in deployment

Answered
Yellowfin tuna posted this in #help-forum
Open in Discord
Yellowfin tunaOP
Greetings,
Sorry for this newbie question, but this is the first time i deploy an app on vercel. The problem i am facing is that upon deployment, I changed all my api routes from https://localhost:3000/ to my deployment URL: https://quotopia-gray.vercel.app/

NEXT_PUBLIC_DEPLOYMENT_BASE_URL = https://quotopia-gray.vercel.app

Sample API Call:
await axios.get(`${process.env.NEXT_PUBLIC_DEPLOYMENT_BASE_URL}/api/feed/${searchParams.page}/${searchParams.query}/${searchParams.category}
    `)
    .then((response) => {
      quotes = response.data.quotes;
      quotesCount = Number(response.data.quotesCount[0]);
    })
    .catch((error) => {
      console.log("Error failed to fetch feed data:" + error);
    });


I created an env variable called NEXT_PUBLIC_BASE_URL and used it in all fetches, but the routes still do not work... Could I get some help please?

Here are the links to the page and to the github repo with all the code! Thanks!!

https://quotopia-gray.vercel.app/
https://github.com/perepalacin/quotopia
Answered by Yellowfin tuna
I already resolved it, appearently the url should be http instead of https according to axios docs! Have a nice day guys!
View full answer

2 Replies

Yellowfin tunaOP
I'm actually able to get data through postman or even loading the production build on localhost...

I have access to the other things stored in my env variables such as auth...
Yellowfin tunaOP
I already resolved it, appearently the url should be http instead of https according to axios docs! Have a nice day guys!
Answer