I have e-commerce nextjs app which have dynamic route pages for cafe menu categories , the menu categories is fetch from backend (django) it's work perfectly when run it in dev
`npm run dev`
but the problem is I get error every time I build next js .
npm run build
the error:
Error occurred prerendering page "/category/bakery". Read more: https://nextjs.org/docs/messages/prerender-error FetchError: request to http://127.0.0.1:8000/menu/api/category/bakery/ failed, reason: connect ECONNREFUSED 127.0.0.1:8000
the structure of next:
- pages
- category * [slug].tsx
slug page :
function Home({ posts, categories }) {
const router = useRouter();
if (router.isFallback) {
return <div>Loading...</div>;
}
return (
.
.
.
.
)
}
export async function getStaticPaths() {
return {
paths: [{ params: { slug: "dessert" } }],
fallback: true,
};
}
export async function getStaticProps({ params }) {
const res = await fetch(`http://127.0.0.1:8000/menu/api/category/${params.slug}/`);
const posts = await res.json();
const ress = await fetch("http://127.0.0.1:8000/menu/api/category/");
const categories = await ress.json();
return {
props: {
posts,
categories,
},
};
}
export default Home
I don't know why this happen I know this question look like duplicate but when I read the previous questions they have different error massage or the question not been solved .
I really appreciate any help I struggle with it for days .