import type { NextConfig } from 'next' import { buildAdminCspHeaders, buildImagesConfig, buildSecurityHeaders, buildUploadSecurityHeaders, withSecurityConfig, } from '@intecion/ipal-kit' import { withPayload } from '@payloadcms/next/withPayload' // @starter:if enforceCsp // CSP enforced: the reference site is the example after the report-only phase (security.md → "ROLL OUT CSP"). const csp = { mode: 'enforce', r2Url: process.env.R2_PUBLIC_URL, reportUri: '/api/csp-report' } as const // @starter:else //: // CSP step 1: report-only. Read the [csp] lines in the logs, add a flag or `extra` per report, then switch to //: // mode: 'enforce' (security.md → "ROLL OUT CSP"; iapl-doctor.json silences the report-only finding until then). //: const csp = { mode: 'report-only', r2Url: process.env.R2_PUBLIC_URL, reportUri: '/api/csp-report' } as const // @starter:endif // Flags = what the site loads: Turnstile on forms, the analytics tools whose IDs are set in Site integrations. const securityHeaders = buildSecurityHeaders({ csp: { ...csp, // @starter:if analytics analytics: true, // @starter:endif // @starter:if metaPixel //: metaPixel: true, // @starter:endif // @starter:if linkedIn //: linkedIn: true, // @starter:endif // @starter:if tiktok //: tiktok: true, // @starter:endif // @starter:if clarity //: clarity: true, // @starter:endif turnstile: true, }, hsts: process.env.NODE_ENV === 'production', }) const nextConfig: NextConfig = { // ALLOW_LOCAL_MEDIA=1 (local / CI production checks only): let next/image optimize files the app serves on localhost images: buildImagesConfig(process.env.ALLOW_LOCAL_MEDIA === '1' ? { production: false } : {}), // Metadata in for crawlers (deployment.md §3a) htmlLimitedBots: /Googlebot|Google-InspectionTool|Storebot-Google|Bingbot|Yandex|DuckDuckBot|Baiduspider|Screaming Frog|AhrefsBot|SemrushBot/i, async headers() { return [ { source: '/:path*', headers: securityHeaders }, { source: '/admin/:path*', headers: buildAdminCspHeaders(csp) }, // after the site-wide rule ...buildUploadSecurityHeaders(), ] }, } // withSecurityConfig OUTSIDE withPayload: no X-Powered-By (Next's and Payload's), and Payload's colour-scheme // client hints (Accept-CH, Critical-CH, Vary) for /admin only, so a public page is requested once (security.md) export default withSecurityConfig(withPayload(nextConfig))