import type { NextConfig } from "next"; const extraConnectSrc = process.env.CSP_CONNECT_SRC ?? ""; // The browser fetches the hub directly, so its origin has to be in connect-src. // Without this every fetch() is blocked by CSP and surfaces as "TypeError: Failed to fetch". const hubUrl = process.env.NEXT_PUBLIC_HUB_URL ?? "http://127.0.0.1:8100"; const hubOrigin = new URL(hubUrl).origin; const securityHeaders = [ { key: "Content-Security-Policy", value: [ "default-src 'self'", "script-src 'self' 'unsafe-eval' 'unsafe-inline'", "style-src 'self' 'unsafe-inline'", "img-src 'self' data: blob:", "font-src 'self'", [ "connect-src 'self'", hubOrigin, "ws://localhost:* ws://127.0.0.1:* wss://localhost:* wss://127.0.0.1:*", extraConnectSrc, ] .filter(Boolean) .join(" "), "frame-ancestors 'none'", ].join("; "), }, { key: "X-Content-Type-Options", value: "nosniff" }, { key: "X-Frame-Options", value: "DENY" }, { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" }, ]; const nextConfig: NextConfig = { output: "standalone", // A stray lockfile in $HOME makes Turbopack guess the wrong workspace root. turbopack: { root: process.cwd() }, env: { NEXT_PUBLIC_HUB_URL: hubUrl, }, async headers() { return [{ source: "/(.*)", headers: securityHeaders }]; }, }; export default nextConfig;