Fixed buildManifest.ts

This commit is contained in:
2026-10-09 19:10:20 +02:00
parent 9b9bbc1a9f
commit 962b9cb640
4 changed files with 78 additions and 22 deletions
+36 -10
View File
@@ -39,6 +39,15 @@ type SettingsShape = {
* import { getCachedPayload } from '@/lib/content'
* import { i18nConfig } from '@/i18n.config'
* export default createManifestHandler({ getCachedPayload, config: i18nConfig })
*
* NOTE on Docker/CI builds: the whole DB access is wrapped in try/catch, so a
* `next build` with no reachable database (the usual Coolify/Docker case) gets
* a minimal valid manifest instead of a crash — same contract as
* generateStaticParams and the sitemap handler. Projects should still mark the
* route dynamic so Next doesn't prerender it at build time:
*
* // app/manifest.ts
* export const dynamic = 'force-dynamic'
*/
export function createManifestHandler(opts: {
config: I18nConfig
@@ -47,18 +56,35 @@ export function createManifestHandler(opts: {
}): () => Promise<Manifest> {
return async () => {
const defaultLocale = getDefaultLocale(opts.config)
const payload = await opts.getCachedPayload()
const settings = (await payload
.findGlobal({
slug: (opts.settingsSlug ?? 'site-settings') as never,
depth: 1,
locale: defaultLocale as never,
})
.catch(() => null)) as null | SettingsShape
const start_url = `/${defaultLocale}`
// Minimal, always-valid manifest. Used both when SiteSettings is empty and
// when the database is unreachable during a build.
const fallback: Manifest = { display: 'standalone', icons: [], start_url }
let settings: null | SettingsShape
try {
// getCachedPayload() ITSELF throws when the DB can't be reached (e.g.
// `getaddrinfo ENOTFOUND` during `docker build`), BEFORE findGlobal runs
// — so the whole thing, not just the query, must sit inside try/catch.
const payload = await opts.getCachedPayload()
settings = (await payload
.findGlobal({
slug: (opts.settingsSlug ?? 'site-settings') as never,
depth: 1,
locale: defaultLocale as never,
})
.catch(() => null)) as null | SettingsShape
} catch (err) {
console.warn(
'[ipal] createManifestHandler: database not reachable during build (Docker/CI) — returning minimal manifest; it fills in at runtime:',
err,
)
return fallback
}
if (!settings) {
return { display: 'standalone', icons: [], start_url }
return fallback
}
const iconSource = settings.favicon ?? settings.logo