import { execSync } from "node:child_process"; import { readFileSync } from "node:fs"; import type { NextConfig } from "next"; // Build stamp shown in the footer: Peppa version (root package.json) and the git commit. // PEP-230: образ платформы собирается из git-архива без .git — коммит приходит из PEPPA_COMMIT (build-arg). const buildCommit = /^[0-9a-f]{7,40}$/.test(process.env.PEPPA_COMMIT ?? "") ? process.env.PEPPA_COMMIT! : ""; const git = (cmd: string) => { try { return execSync(`git ${cmd}`, { encoding: "utf8" }).trim(); } catch { return ""; } }; const version = (JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")) as { version?: string }).version ?? "0.0.0"; const config: NextConfig = { // Workspace packages ship TypeScript sources. // `next dev` behind Traefik (pre-launch live mode): let the public host load dev assets and HMR. allowedDevOrigins: ["peppa.telecom.quest"], // Forwarded browser logs land in .next/dev/logs; the watcher picked that up as a change and the // page reloaded in a loop (every reload logs again). Errors still reach the terminal. // PEP-119: nothing from the browser is forwarded at all — an error that happens on every load // (a stale tab, a hydration mismatch) wrote to the log on every load and the reload never // stopped; that locked everyone out on 15.11. Browser errors go to Bugsink instead (PEP-91). logging: { browserToTerminal: false }, // PEP-144: with the dev MCP server on (the default) Next also writes every browser and server // log line to .next/dev/logs/next-development.log. On the live site each open tab logged on // every refresh, the write was picked up as a change, the page refreshed and logged again — // several rebuilds a second, pages never settled. Off: no log file, no /_next/mcp endpoint. experimental: { mcpServer: false }, // No Next.js badge and no «Issue» pill on the live site: a product manager must not see dev tools. devIndicators: false, // Dev chunks keep their names between edits; Cloudflare turns the dev server's `no-cache` into a // 4 h browser cache, so a reload ran stale code. `private, no-store` is passed through as is. async headers() { // The service worker must not sit in a browser/CDN cache, or fixes to it never arrive (PEP-55). const sw = { source: "/sw.js", headers: [{ key: "Cache-Control", value: "private, no-cache, max-age=0" }] }; // PEP-133: browser-side hardening on every page. A full script CSP is not set — Next inlines // its bootstrap scripts; framing, base tag and plugins are locked instead. const secure = [ { key: "X-Content-Type-Options", value: "nosniff" }, { key: "X-Frame-Options", value: "DENY" }, { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" }, { key: "Permissions-Policy", value: "camera=(), geolocation=(), payment=(), usb=(), microphone=(self)" }, { key: "Content-Security-Policy", value: "frame-ancestors 'none'; base-uri 'self'; object-src 'none'" }, ...(process.env.NODE_ENV === "development" ? [] : [{ key: "Strict-Transport-Security", value: "max-age=15552000" }]), ]; const all = { source: "/:path*", headers: secure }; return process.env.NODE_ENV === "development" ? [all, { source: "/_next/static/:path*", headers: [{ key: "Cache-Control", value: "private, no-store" }] }, sw] : [all, sw]; }, // PEP-212: the code-mode sandbox (QuickJS wasm) loads its .wasm file itself — it must not be bundled. // PEP-251: Access Hub drivers load on first use and stay out of the bundle. serverExternalPackages: ["quickjs-emscripten", "ws", "pg", "mysql2", "ssh2", "imapflow", "nodemailer"], transpilePackages: ["@peppa/db", "@peppa/shared", "@peppa/core", "@peppa/runner", "@peppa/mcp"], env: { NEXT_PUBLIC_PEPPA_VERSION: version, NEXT_PUBLIC_PEPPA_COMMIT: git("rev-parse --short HEAD") || buildCommit.slice(0, 8), NEXT_PUBLIC_PEPPA_COMMIT_FULL: git("rev-parse HEAD") || buildCommit, NEXT_PUBLIC_PEPPA_COMMIT_DATE: git("log -1 --format=%cI"), NEXT_PUBLIC_PEPPA_DIRTY: git("status --porcelain --untracked-files=no") ? "1" : "", }, }; export default config;