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 */ } } } const API_URL = process.env.API_URL ?? 'http://127.0.0.1:8311'; const nextConfig: NextConfig = { reactStrictMode: true, poweredByHeader: false, allowedDevOrigins: ['127.0.0.1', 'localhost'], outputFileTracingRoot: path.resolve(__dirname, '../..'), experimental: { optimizePackageImports: ['lucide-react', 'three', '@react-three/drei'], }, // Browser-side fetches go to the same origin; the FastAPI service is loopback-only. async rewrites() { return [ { source: '/api/v1/:path*', destination: `${API_URL}/api/v1/:path*` }, { source: '/health', destination: `${API_URL}/health` }, ]; }, async redirects() { return [ { source: '/satellites/:slug((?!facets$)[^/]+)', destination: '/satellite/:slug', permanent: true }, { source: '/constellations/:slug', destination: '/constellation/:slug', permanent: true }, { source: '/operators/:slug', destination: '/operator/:slug', permanent: true }, { source: '/countries/:slug', destination: '/country/:slug', permanent: true }, ]; }, async headers() { const PUBLIC_CACHE = { key: 'Cache-Control', value: 'public, s-maxage=600, stale-while-revalidate=3600' }; 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: '/satellite/:path*', headers: [PUBLIC_CACHE] }, { source: '/constellation/:path*', headers: [PUBLIC_CACHE] }, { source: '/operator/:path*', headers: [PUBLIC_CACHE] }, { source: '/country/:path*', headers: [PUBLIC_CACHE] }, { source: '/api/:path*', headers: [NO_STORE] }, { source: '/admin/:path*', headers: [NO_STORE] }, ]; }, }; export default nextConfig;