import { withFontCopy } from '@lumina/island/tools/font-copy-plugin'; import { withIconSprite } from '@lumina/island/tools/icon-sprite-plugin'; import { SERVICE_WORKER_HEADERS, SERVICE_WORKER_URL, writeServiceWorker, } from '@lumina/libs/pwa/plugin'; import type { NextConfig } from 'next'; import path from 'node:path'; // Libs compile from source outside the app, so tracing and Turbopack both start at the workspace root. const workspaceRoot = path.join(__dirname, '../..'); // Fonts and the icon sprite keep fixed names; a changed font gets a new name, and the sprite a new // ?v= (0011, 0012). Next serves public/ with max-age=0, so without this every visit asks for them again. const immutable = [ { key: 'Cache-Control', value: 'public, max-age=31536000, immutable' }, ]; // No page may be framed by another site (checkout, finance and account pages act on a click), and // the browser never guesses a type or sends full URLs to other sites. const security = [ { key: 'Content-Security-Policy', value: "frame-ancestors 'none'" }, { key: 'X-Frame-Options', value: 'DENY' }, { key: 'X-Content-Type-Options', value: 'nosniff' }, { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' }, ]; // The edge nginx (0001) passes a streamed page on as each part renders instead of buffering it whole. const streaming = [{ key: 'X-Accel-Buffering', value: 'no' }]; const nextConfig: NextConfig = { // The image runs .next/standalone/apps//server.js with only the traced files; it never loads // this file at runtime, so the plugins below never run in the container. output: 'standalone', outputFileTracingRoot: workspaceRoot, turbopack: { root: workspaceRoot }, poweredByHeader: false, // Every visitor gets the metadata in , where Chrome looks for the manifest and Safari for // its home-screen tags; Next.js would otherwise stream it to the end of (0054). htmlLimitedBots: /.*/, // Workspace packages export TypeScript source, so Next.js compiles them. transpilePackages: [ '@lumina/market', '@lumina/integrations', '@lumina/island', '@lumina/libs', '@lumina/tools', ], async headers() { // Only Next calls `headers()`, on `next dev` and `next build`, so the worker is written here, as // island's plugins write theirs. Next runs from the app's folder, as every Nx target does. writeServiceWorker({ publicDir: path.join(process.cwd(), 'public') }); return [ { source: '/:path*', headers: [...security, ...streaming] }, { source: '/fonts/:path*', headers: immutable }, { source: '/icons/:path*', headers: immutable }, // Revalidated on every update check, so a new worker reaches visitors at their next // navigation; never immutable. /sw.js is never renamed or removed (pwa lib). { source: SERVICE_WORKER_URL, headers: Object.entries(SERVICE_WORKER_HEADERS).map(([key, value]) => ({ key, value, })), }, ]; }, // A channel lives at `/channels/username` only (0064). Links people kept or were sent as // `/@username` (the old address, still in SMS and notifications) move there for good, query kept. async redirects() { return [ { source: '/@:username/:path*', destination: '/channels/:username/:path*', permanent: true, }, ]; }, }; // On next dev and next build, island's plugins write the fonts and icon sprite into public/ // under their fixed names, with no hash (0012). export default withIconSprite(withFontCopy(nextConfig));