Remove generateStaticParams to enable compiling. Else, it sets the url as localhost in the deployement or does not build as it cannot access the container during build.

This commit is contained in:
Amritanshu Agrawal 2024-10-17 08:43:02 +05:30
parent 8589d0f784
commit 0deee17031

View File

@ -1,4 +1,4 @@
import { HttpTypes } from '@medusajs/types';
// import { HttpTypes } from '@medusajs/types';
import { FC } from 'react';
import ProductDetails from './ProductDetails';
@ -8,27 +8,27 @@ interface ProductPageProps {
handle: string;
};
}
export async function generateStaticParams() {
// Fetch the list of products
const products: HttpTypes.StoreProduct[] = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/products`, {
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'x-publishable-api-key': process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY as string,
},
})
.then((res) => res.json())
.then((data) => data.products);
// export async function generateStaticParams() {
// // Fetch the list of products
// const products: HttpTypes.StoreProduct[] = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/store/products`, {
// credentials: 'include',
// headers: {
// 'Content-Type': 'application/json',
// 'x-publishable-api-key': process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY as string,
// },
// })
// .then((res) => res.json())
// .then((data) => data.products);
if (!products) {
return [];
}
// Generate static params based on product handles
const staticParams = products.map((product) => ({
handle: product.handle,
}));
return staticParams;
}
// if (!products) {
// return [];
// }
// // Generate static params based on product handles
// const staticParams = products.map((product) => ({
// handle: product.handle,
// }));
// return staticParams;
// }
const ProductPage: FC<ProductPageProps> = ({ params }) => {
const { handle } = params; // Extract the handle from the params