import type { NextConfig } from 'next'; import { existsSync } from 'node:fs'; import path from 'node:path'; // Monorepo: a single `.env` lives at the repository root; Next only reads the app directory. for (const candidate of [path.resolve(process.cwd(), '../../.env'), path.resolve(process.cwd(), '.env')]) { if (existsSync(candidate)) { try { process.loadEnvFile(candidate); } catch { /* ignore malformed env */ } } } // Browser code always calls relative `/api/...`; in dev Next proxies it to the FastAPI service (or the mock). // In production the edge Caddy routes `/api/*` straight to the API, so this rewrite is a fallback only. const API_URL = process.env.API_URL ?? 'http://127.0.0.1:8352'; const nextConfig: NextConfig = { reactStrictMode: true, poweredByHeader: false, output: 'standalone', allowedDevOrigins: ['127.0.0.1', 'localhost'], outputFileTracingRoot: path.resolve(__dirname, '../..'), experimental: { optimizePackageImports: ['lucide-react'], }, async rewrites() { return [{ source: '/api/:path*', destination: `${API_URL}/api/:path*` }]; }, async headers() { const PUBLIC_CACHE = { key: 'Cache-Control', value: 'public, s-maxage=60, stale-while-revalidate=300' }; const NO_STORE = { key: 'Cache-Control', value: 'private, no-store' }; return [ { source: '/(.*)', headers: [ { key: 'X-Content-Type-Options', value: 'nosniff' }, { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' }, { key: 'X-Frame-Options', value: 'SAMEORIGIN' }, { key: 'Permissions-Policy', value: 'camera=(), microphone=(), geolocation=()' }, { key: 'Strict-Transport-Security', value: 'max-age=31536000; includeSubDomains' }, ], }, { source: '/country/:path*', headers: [PUBLIC_CACHE] }, { source: '/internet/:path*', headers: [PUBLIC_CACHE] }, { source: '/asn/:path*', headers: [PUBLIC_CACHE] }, { source: '/service/:path*', headers: [PUBLIC_CACHE] }, { source: '/event/:path*', headers: [PUBLIC_CACHE] }, { source: '/history/:path*', headers: [PUBLIC_CACHE] }, { source: '/history', headers: [PUBLIC_CACHE] }, { source: '/api/:path*', headers: [NO_STORE] }, { source: '/admin/:path*', headers: [NO_STORE] }, { source: '/admin', headers: [NO_STORE] }, ]; }, }; export default nextConfig;