import { getDefaultLocale } from '../i18n/index.js'; /** * Builds a Next Web App Manifest from SiteSettings — replaces the ~50 lines of * icon/mimeType parsing copied into every project's manifest.ts. Values come * from the panel; missing fields are omitted (no hardcoded client data). * * // app/manifest.ts * import { createManifestHandler } from '@intecion/ipal-kit' * 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 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 fallback; } const iconSource = settings.favicon ?? settings.logo; const icons = []; if (iconSource?.url) { const type = iconSource.mimeType ?? (iconSource.url.endsWith('.svg') ? 'image/svg+xml' : undefined); const isSvg = type === 'image/svg+xml'; const size = iconSource.width && iconSource.height ? `${iconSource.width}x${iconSource.height}` : undefined; icons.push({ src: iconSource.url, ...isSvg ? { sizes: 'any' } : size ? { sizes: size } : {}, ...type ? { type } : {} }); } return { ...settings.siteName ? { name: settings.siteName, short_name: settings.siteName } : {}, display: 'standalone', start_url, ...settings.backgroundColor ? { background_color: settings.backgroundColor } : {}, ...settings.themeColor ? { theme_color: settings.themeColor } : {}, icons }; }; } //# sourceMappingURL=buildManifest.js.map