I made an API route in the pages folder on a NextJS project. It works fine, I can fetch data from it by going to the URL directly such as http://localhost:3000/api/tv/popular. I want to fetch the data in getStaticProps and then forward to the components. It works fine if I do it this way
export const getStaticProps: GetStaticProps = async (ctx) => {
const { data } = await axios.get("http://localhost:3000/api/tv/popular");
return {
props: {
popularContent: data,
},
};
};
But if I remove local host and send request to axios.get("/api/tv/popular")
it fails.
Why is this, I thought this should be possible in NextJs to not include localhost