fix: wrap generateStaticParams in try/catch to survive build without DB
Some checks failed
Deploy to production / SSH deploy to VPS (push) Has been cancelled
Some checks failed
Deploy to production / SSH deploy to VPS (push) Has been cancelled
During Docker build the `db` host doesn't exist in the build network, so any attempt to query Postgres in generateStaticParams fails. With the try/catch, blog pages fall back to [] (rendered on demand) and service pages fall back to hardcoded SERVICES_FALLBACK slugs so static pages are still pre-generated even without a live DB. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0f8de6479d
commit
7b6cfaa5c2
2 changed files with 16 additions and 6 deletions
|
|
@ -29,8 +29,13 @@ function formatDate(iso: string | null | undefined): string {
|
|||
}
|
||||
|
||||
export async function generateStaticParams() {
|
||||
const posts = await getPublishedPosts(100);
|
||||
return posts.map((p) => ({ slug: p.slug }));
|
||||
try {
|
||||
const posts = await getPublishedPosts(100);
|
||||
return posts.map((p) => ({ slug: p.slug }));
|
||||
} catch {
|
||||
// DB unavailable at build time (no `db` host in Docker build network) — pages render on demand
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
|
|
|
|||
|
|
@ -214,10 +214,15 @@ const SERVICES_FALLBACK: Record<string, DisplayService> = {
|
|||
};
|
||||
|
||||
export async function generateStaticParams() {
|
||||
const services = await getPublishedServices(100);
|
||||
const cmsSlugSet = new Set(services.map((s) => s.slug));
|
||||
const fallbackSlugs = Object.keys(SERVICES_FALLBACK).filter((s) => !cmsSlugSet.has(s));
|
||||
return [...services.map((s) => ({ slug: s.slug })), ...fallbackSlugs.map((s) => ({ slug: s }))];
|
||||
try {
|
||||
const services = await getPublishedServices(100);
|
||||
const cmsSlugSet = new Set(services.map((s) => s.slug));
|
||||
const fallbackSlugs = Object.keys(SERVICES_FALLBACK).filter((s) => !cmsSlugSet.has(s));
|
||||
return [...services.map((s) => ({ slug: s.slug })), ...fallbackSlugs.map((s) => ({ slug: s }))];
|
||||
} catch {
|
||||
// DB unavailable at build time — pre-render fallback slugs only; CMS pages render on demand
|
||||
return Object.keys(SERVICES_FALLBACK).map((s) => ({ slug: s }));
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue