Next.js Discord

Discord Forum

generateStaticParams in docker image

Unanswered
Bedlington Terrier posted this in #help-forum
Open in Discord
Bedlington TerrierOP
So trying to generate static pages for my application to make it more snappy. But I'm having issues when trying to generate the pages in the docker build. As far as I know, running docker build -t myapp . , during runtime the node-server is not running and therefore we can't make api requests? Is that correct? Seems a little wierd not be able to build a image beacuase docker build can't find the api which makes up for the data for the pages. Anyone built a Nextjs-app using generateStaticParams running in a docker container?

Example of my page /app/store/product/[slug]/page.tsx
export async function generateStaticParams() {
  try {
   const res = await getPrintifyProducts();
   if (!res.ok) {
     console.error("[generateStaticParams] Response not OK:", res.status, res.statusText);
     return [];
   }
   const data = await res.json();
   const products: PrintifyProduct[] = data; // Assuming the response has a 'data' field containing the products
   if (!products || products.length < 1) {
       return [];
   }
   return products.map((product: PrintifyProduct) => ({
     slug: product.title.replace(/ /g, "-") //Names have spaces "%20"
   }));
   } catch (error) {
     return [];
   }
}
export default async function ProductDetails({
    params,
    searchParams,
}: {
    params: { slug: string }; // Params will contain the slug from the dynamic route
    searchParams: { color?: string; size?: string }; // Query params
}) {
    const { slug } = params; // Get the slug from the dynamic route
    const { color, size } = searchParams; // Get the color and size from the query params
    try {
        // Fetch the products
        const res = await getPrintifyProducts();
        if (!res.ok) {
            return [];
        }
        const data = await res.json();
        const products: PrintifyProduct[] = data; // Assuming the response has a 'data' field containing the products
        if (!products || products.length < 1) {
            return [];
        }

0 Replies