1

I have used the below code. It is working with npm run dev. But while doing the npm run build it is getting failed due the network failed error:

export async function getStaticProps({ params }) {
  let skuId = params.sku;
  const res = await axios.get(`http://localhost:3001/api/get/product/${skuId}`);
  const data = await res.data;

  return {
    props: {
      post: data
    }
  }
}

Vinit
  • 11
  • 1
  • I"m assuming "http://localhost:3001/api/get/product/${skuId}" is next.js endpoint. If that is the case, it won't be available at build time, but only in runtime. – zoran jeremic Jul 28 '20 at 14:35
  • Yes it is nextjs endpoint. If it is not available at build time then we cannot generate the static pages. What is the alternative we can use to achieve this? – Vinit Jul 29 '20 at 05:12
  • 1
    That depends on your design and where are those products available. You can retrieve it from you local file system, e.g. from json files if those products information are static data, from database or eventually from external endpoints which are available at build time. – zoran jeremic Jul 29 '20 at 18:54

0 Answers0