From 962b9cb6400381cd9da9b3615932e011ffa56d78 Mon Sep 17 00:00:00 2001 From: rasm-its Date: Fri, 9 Oct 2026 19:10:20 +0200 Subject: [PATCH] Fixed buildManifest.ts --- dist/modules/seo/buildManifest.d.ts | 9 ++++++ dist/modules/seo/buildManifest.js | 43 ++++++++++++++++++------- dist/modules/seo/buildManifest.js.map | 2 +- src/modules/seo/buildManifest.ts | 46 +++++++++++++++++++++------ 4 files changed, 78 insertions(+), 22 deletions(-) diff --git a/dist/modules/seo/buildManifest.d.ts b/dist/modules/seo/buildManifest.d.ts index 7f413c2..b1a8b11 100644 --- a/dist/modules/seo/buildManifest.d.ts +++ b/dist/modules/seo/buildManifest.d.ts @@ -24,6 +24,15 @@ type Manifest = { * 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 declare function createManifestHandler(opts: { config: I18nConfig; diff --git a/dist/modules/seo/buildManifest.js b/dist/modules/seo/buildManifest.js index 074ac0c..e2134ae 100644 --- a/dist/modules/seo/buildManifest.js +++ b/dist/modules/seo/buildManifest.js @@ -9,22 +9,43 @@ import { getDefaultLocale } from '../i18n/index.js'; * 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) { return async ()=>{ const defaultLocale = getDefaultLocale(opts.config); - const payload = await opts.getCachedPayload(); - const settings = await payload.findGlobal({ - slug: opts.settingsSlug ?? 'site-settings', - depth: 1, - locale: defaultLocale - }).catch(()=>null); 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 = { + display: 'standalone', + icons: [], + start_url + }; + let settings; + 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', + depth: 1, + locale: defaultLocale + }).catch(()=>null); + } 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; const icons = []; diff --git a/dist/modules/seo/buildManifest.js.map b/dist/modules/seo/buildManifest.js.map index 3347cfa..790ca61 100644 --- a/dist/modules/seo/buildManifest.js.map +++ b/dist/modules/seo/buildManifest.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/modules/seo/buildManifest.ts"],"sourcesContent":["import type { BasePayload } from 'payload'\n\nimport type { I18nConfig } from '../i18n/index.js'\n\nimport { getDefaultLocale } from '../i18n/index.js'\n\ntype MediaLike =\n | { height?: null | number; mimeType?: null | string; url?: null | string; width?: null | number }\n | null\n | undefined\n\ntype ManifestIcon = { sizes?: string; src: string; type?: string }\n\ntype Manifest = {\n background_color?: string\n display: 'standalone'\n icons: ManifestIcon[]\n name?: string\n short_name?: string\n start_url: string\n theme_color?: string\n}\n\ntype SettingsShape = {\n backgroundColor?: null | string\n favicon?: MediaLike\n logo?: MediaLike\n siteName?: null | string\n themeColor?: null | string\n}\n\n/**\n * Builds a Next Web App Manifest from SiteSettings — replaces the ~50 lines of\n * icon/mimeType parsing copied into every project's manifest.ts. Values come\n * from the panel; missing fields are omitted (no hardcoded client data).\n *\n * // app/manifest.ts\n * import { createManifestHandler } from '@intecion/ipal-kit'\n * import { getCachedPayload } from '@/lib/content'\n * import { i18nConfig } from '@/i18n.config'\n * export default createManifestHandler({ getCachedPayload, config: i18nConfig })\n */\nexport function createManifestHandler(opts: {\n config: I18nConfig\n getCachedPayload: () => Promise\n settingsSlug?: string\n}): () => Promise {\n return async () => {\n const defaultLocale = getDefaultLocale(opts.config)\n const payload = await opts.getCachedPayload()\n const settings = (await payload\n .findGlobal({\n slug: (opts.settingsSlug ?? 'site-settings') as never,\n depth: 1,\n locale: defaultLocale as never,\n })\n .catch(() => null)) as null | SettingsShape\n\n const start_url = `/${defaultLocale}`\n if (!settings) {\n return { display: 'standalone', icons: [], start_url }\n }\n\n const iconSource = settings.favicon ?? settings.logo\n const icons: ManifestIcon[] = []\n if (iconSource?.url) {\n const type =\n iconSource.mimeType ?? (iconSource.url.endsWith('.svg') ? 'image/svg+xml' : undefined)\n const isSvg = type === 'image/svg+xml'\n const size =\n iconSource.width && iconSource.height\n ? `${iconSource.width}x${iconSource.height}`\n : undefined\n icons.push({\n src: iconSource.url,\n ...(isSvg ? { sizes: 'any' } : size ? { sizes: size } : {}),\n ...(type ? { type } : {}),\n })\n }\n\n return {\n ...(settings.siteName ? { name: settings.siteName, short_name: settings.siteName } : {}),\n display: 'standalone',\n start_url,\n ...(settings.backgroundColor ? { background_color: settings.backgroundColor } : {}),\n ...(settings.themeColor ? { theme_color: settings.themeColor } : {}),\n icons,\n }\n }\n}\n"],"names":["getDefaultLocale","createManifestHandler","opts","defaultLocale","config","payload","getCachedPayload","settings","findGlobal","slug","settingsSlug","depth","locale","catch","start_url","display","icons","iconSource","favicon","logo","url","type","mimeType","endsWith","undefined","isSvg","size","width","height","push","src","sizes","siteName","name","short_name","backgroundColor","background_color","themeColor","theme_color"],"mappings":"AAIA,SAASA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AkB7B,SAAS4B,eAAe;YAAC,IAAI,CAAC,CAAC;YAClF,GAAI5B,SAAS8B,UAAU,GAAG;gBAAEC,aAAa/B,SAAS8B,UAAU;YAAC,IAAI,CAAC,CAAC;YACnErB;QACF;IACF;AACF"} \ No newline at end of file +{"version":3,"sources":["../../../src/modules/seo/buildManifest.ts"],"sourcesContent":["import type { BasePayload } from 'payload'\n\nimport type { I18nConfig } from '../i18n/index.js'\n\nimport { getDefaultLocale } from '../i18n/index.js'\n\ntype MediaLike =\n | { height?: null | number; mimeType?: null | string; url?: null | string; width?: null | number }\n | null\n | undefined\n\ntype ManifestIcon = { sizes?: string; src: string; type?: string }\n\ntype Manifest = {\n background_color?: string\n display: 'standalone'\n icons: ManifestIcon[]\n name?: string\n short_name?: string\n start_url: string\n theme_color?: string\n}\n\ntype SettingsShape = {\n backgroundColor?: null | string\n favicon?: MediaLike\n logo?: MediaLike\n siteName?: null | string\n themeColor?: null | string\n}\n\n/**\n * Builds a Next Web App Manifest from SiteSettings — replaces the ~50 lines of\n * icon/mimeType parsing copied into every project's manifest.ts. Values come\n * from the panel; missing fields are omitted (no hardcoded client data).\n *\n * // app/manifest.ts\n * import { createManifestHandler } from '@intecion/ipal-kit'\n * import { getCachedPayload } from '@/lib/content'\n * import { i18nConfig } from '@/i18n.config'\n * export default createManifestHandler({ getCachedPayload, config: i18nConfig })\n *\n * NOTE on Docker/CI builds: the whole DB access is wrapped in try/catch, so a\n * `next build` with no reachable database (the usual Coolify/Docker case) gets\n * a minimal valid manifest instead of a crash — same contract as\n * generateStaticParams and the sitemap handler. Projects should still mark the\n * route dynamic so Next doesn't prerender it at build time:\n *\n * // app/manifest.ts\n * export const dynamic = 'force-dynamic'\n */\nexport function createManifestHandler(opts: {\n config: I18nConfig\n getCachedPayload: () => Promise\n settingsSlug?: string\n}): () => Promise {\n return async () => {\n const defaultLocale = getDefaultLocale(opts.config)\n const start_url = `/${defaultLocale}`\n\n // Minimal, always-valid manifest. Used both when SiteSettings is empty and\n // when the database is unreachable during a build.\n const fallback: Manifest = { display: 'standalone', icons: [], start_url }\n\n let settings: null | SettingsShape\n try {\n // getCachedPayload() ITSELF throws when the DB can't be reached (e.g.\n // `getaddrinfo ENOTFOUND` during `docker build`), BEFORE findGlobal runs\n // — so the whole thing, not just the query, must sit inside try/catch.\n const payload = await opts.getCachedPayload()\n settings = (await payload\n .findGlobal({\n slug: (opts.settingsSlug ?? 'site-settings') as never,\n depth: 1,\n locale: defaultLocale as never,\n })\n .catch(() => null)) as null | SettingsShape\n } catch (err) {\n console.warn(\n '[ipal] createManifestHandler: database not reachable during build (Docker/CI) — returning minimal manifest; it fills in at runtime:',\n err,\n )\n return fallback\n }\n\n if (!settings) {\n return fallback\n }\n\n const iconSource = settings.favicon ?? settings.logo\n const icons: ManifestIcon[] = []\n if (iconSource?.url) {\n const type =\n iconSource.mimeType ?? (iconSource.url.endsWith('.svg') ? 'image/svg+xml' : undefined)\n const isSvg = type === 'image/svg+xml'\n const size =\n iconSource.width && iconSource.height\n ? `${iconSource.width}x${iconSource.height}`\n : undefined\n icons.push({\n src: iconSource.url,\n ...(isSvg ? { sizes: 'any' } : size ? { sizes: size } : {}),\n ...(type ? { type } : {}),\n })\n }\n\n return {\n ...(settings.siteName ? { name: settings.siteName, short_name: settings.siteName } : {}),\n display: 'standalone',\n start_url,\n ...(settings.backgroundColor ? { background_color: settings.backgroundColor } : {}),\n ...(settings.themeColor ? { theme_color: settings.themeColor } : {}),\n icons,\n }\n }\n}\n"],"names":["getDefaultLocale","createManifestHandler","opts","defaultLocale","config","start_url","fallback","display","icons","settings","payload","getCachedPayload","findGlobal","slug","settingsSlug","depth","locale","catch","err","console","warn","iconSource","favicon","logo","url","type","mimeType","endsWith","undefined","isSvg","size","width","height","push","src","sizes","siteName","name","short_name","backgroundColor","background_color","themeColor","theme_color"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,mBAAkB;AA2BnD;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASC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AAQ;gBAAEE,YAAY7B,SAAS2B,QAAQ;YAAC,IAAI,CAAC,CAAC;YACvF7B,SAAS;YACTF;YACA,GAAII,SAAS8B,eAAe,GAAG;gBAAEC,kBAAkB/B,SAAS8B,eAAe;YAAC,IAAI,CAAC,CAAC;YAClF,GAAI9B,SAASgC,UAAU,GAAG;gBAAEC,aAAajC,SAASgC,UAAU;YAAC,IAAI,CAAC,CAAC;YACnEjC;QACF;IACF;AACF"} \ No newline at end of file diff --git a/src/modules/seo/buildManifest.ts b/src/modules/seo/buildManifest.ts index 005de51..1b081a9 100644 --- a/src/modules/seo/buildManifest.ts +++ b/src/modules/seo/buildManifest.ts @@ -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 { 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