import type { NextConfig } from "next"; const isProd = process.env.NODE_ENV === "production"; const staging = process.env.STAGING_MODE === "1"; const securityHeaders = [ { key: "X-Content-Type-Options", value: "nosniff" }, { key: "X-Frame-Options", value: "SAMEORIGIN" }, { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" }, { key: "Permissions-Policy", value: "camera=(), microphone=(), geolocation=(), browsing-topics=()" }, { key: "Content-Security-Policy", value: [ "default-src 'self'", `script-src 'self'${isProd ? "" : " 'unsafe-eval'"} 'unsafe-inline'`, "style-src 'self' 'unsafe-inline'", "img-src 'self' data: blob:", "font-src 'self' data:", "connect-src 'self'", "frame-src 'self' blob:", "object-src 'self'", "base-uri 'self'", "form-action 'self'", "frame-ancestors 'self'", ...(isProd ? ["upgrade-insecure-requests"] : []), ].join("; "), }, ...(isProd ? [{ key: "Strict-Transport-Security", value: "max-age=31536000; includeSubDomains" }] : []), ...(staging ? [{ key: "X-Robots-Tag", value: "noindex, nofollow" }] : []), ]; const nextConfig: NextConfig = { distDir: process.env.NEXT_DIST_DIR || ".next", reactStrictMode: true, poweredByHeader: false, serverExternalPackages: ["pg", "pino", "@node-rs/argon2", "pdfjs-dist", "pdf-lib", "drizzle-orm"], experimental: { serverActions: { bodySizeLimit: "2mb" } }, async headers() { return [ { source: "/(.*)", headers: securityHeaders }, { source: "/papers/:path*", headers: [{ key: "Cache-Control", value: "public, max-age=31536000, immutable" }], }, ]; }, }; export default nextConfig;