fix createContentHelpers.ts
This commit is contained in:
+10
@@ -141,6 +141,7 @@ import { buildRobots, buildSitemapEntries } from '../seo/index.js';
|
|||||||
* // app/(frontend)/[[...slug]]/page.tsx (or [locale]/[[...slug]])
|
* // app/(frontend)/[[...slug]]/page.tsx (or [locale]/[[...slug]])
|
||||||
* export { generateStaticParams } from '@/lib/content'
|
* export { generateStaticParams } from '@/lib/content'
|
||||||
*/ const generateStaticParams = async ()=>{
|
*/ const generateStaticParams = async ()=>{
|
||||||
|
try {
|
||||||
const payload = await getCachedPayload();
|
const payload = await getCachedPayload();
|
||||||
const locales = i18n ? i18n.locales.map((l)=>l.code) : [
|
const locales = i18n ? i18n.locales.map((l)=>l.code) : [
|
||||||
undefined
|
undefined
|
||||||
@@ -214,6 +215,15 @@ import { buildRobots, buildSitemapEntries } from '../seo/index.js';
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
|
} catch (err) {
|
||||||
|
// DB unreachable — typically a container build (Docker/Coolify/CI) with no
|
||||||
|
// database network. Return [] so the build doesn't crash: Next falls back
|
||||||
|
// to on-demand rendering for the routes, which fill in once the DB is
|
||||||
|
// reachable at runtime. Without this every project would need its own
|
||||||
|
// try/catch here. (Same graceful-degradation as the sitemap handler.)
|
||||||
|
console.warn('[ipal] generateStaticParams: database not reachable during build ' + '(Docker/CI) — returning empty params; routes render on-demand at runtime:', err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
generateStaticParams,
|
generateStaticParams,
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -145,6 +145,29 @@ sitemap/robots → force-dynamic (bo generują przy żądaniu). Nie mieszaj na j
|
|||||||
trasie. Treść z panelu: ISR = redaktor czeka do rewalidacji; rozważ on-demand
|
trasie. Treść z panelu: ISR = redaktor czeka do rewalidacji; rozważ on-demand
|
||||||
revalidation (hook afterChange → revalidatePath). Patrz seo.md, HOOKS.md.
|
revalidation (hook afterChange → revalidatePath). Patrz seo.md, HOOKS.md.
|
||||||
|
|
||||||
|
## 3a3. SSG a dostęp do bazy przy buildzie (WAŻNE dla SEO)
|
||||||
|
|
||||||
|
`generateStaticParams` (z lib/content) prerenderuje strony jako SSG — head
|
||||||
|
synchroniczny, SEO 100/100. ALE żeby prerenderować, **build musi mieć dostęp do
|
||||||
|
bazy** (generateStaticParams czyta strony z bazy w czasie buildu).
|
||||||
|
|
||||||
|
- **Build MA dostęp do bazy** (baza w tej samej sieci Docker, dostępna w build
|
||||||
|
stage) → strony prerenderowane jako SSG (`●`), head synchroniczny → SEO OK ✓
|
||||||
|
- **Build NIE MA dostępu** (izolowany build stage) → generateStaticParams zwraca
|
||||||
|
`[]` (plugin łapie błąd, build nie pada), ale strony renderują się on-demand
|
||||||
|
(dynamicznie) → head może streamować do body → problem SEO wraca ✗
|
||||||
|
|
||||||
|
Plugin zabezpiecza build przed CRASHEM (try/catch → `[]`), ale to NIE zastępuje
|
||||||
|
dostępu do bazy. **Dla pełnego SSG/SEO zapewnij, że build kontenerowy widzi bazę.**
|
||||||
|
|
||||||
|
W Coolify/Docker: baza (Mongo/Postgres) powinna być dostępna podczas `pnpm build`,
|
||||||
|
nie tylko w runtime. Jeśli build jest w izolowanej sieci — rozważ:
|
||||||
|
- uruchom bazę w tej samej sieci Docker co build stage, albo
|
||||||
|
- build z DATABASE_URI wskazującym na dostępną bazę (nie wewnętrzny host niedostępny w buildzie).
|
||||||
|
|
||||||
|
Weryfikacja: po buildzie `pnpm build` pokazuje trasy jako `●` (SSG), nie `ƒ`
|
||||||
|
(Dynamic). Jeśli `ƒ` mimo generateStaticParams → build nie miał dostępu do bazy.
|
||||||
|
|
||||||
## 3b. Pułapka: prerender tras zależnych od bazy (KONIECZNE)
|
## 3b. Pułapka: prerender tras zależnych od bazy (KONIECZNE)
|
||||||
|
|
||||||
Next domyślnie **prerenderuje** trasy typu `sitemap.ts` w czasie `next build` —
|
Next domyślnie **prerenderuje** trasy typu `sitemap.ts` w czasie `next build` —
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ export function createContentHelpers({
|
|||||||
const generateStaticParams = async (): Promise<
|
const generateStaticParams = async (): Promise<
|
||||||
Array<{ locale: string; slug: string[] } | { slug: string[] }>
|
Array<{ locale: string; slug: string[] } | { slug: string[] }>
|
||||||
> => {
|
> => {
|
||||||
|
try {
|
||||||
const payload = await getCachedPayload()
|
const payload = await getCachedPayload()
|
||||||
const locales = i18n ? i18n.locales.map((l) => l.code) : [undefined]
|
const locales = i18n ? i18n.locales.map((l) => l.code) : [undefined]
|
||||||
const singleLocale = !i18n || i18n.locales.length === 1
|
const singleLocale = !i18n || i18n.locales.length === 1
|
||||||
@@ -265,6 +266,19 @@ export function createContentHelpers({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
} catch (err) {
|
||||||
|
// DB unreachable — typically a container build (Docker/Coolify/CI) with no
|
||||||
|
// database network. Return [] so the build doesn't crash: Next falls back
|
||||||
|
// to on-demand rendering for the routes, which fill in once the DB is
|
||||||
|
// reachable at runtime. Without this every project would need its own
|
||||||
|
// try/catch here. (Same graceful-degradation as the sitemap handler.)
|
||||||
|
console.warn(
|
||||||
|
'[ipal] generateStaticParams: database not reachable during build ' +
|
||||||
|
'(Docker/CI) — returning empty params; routes render on-demand at runtime:',
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
return []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user