SPB Git

spb/ai-atlas

Public
2.3 KB · 61 lines typescript
1import type { NextConfig } from 'next';2import { existsSync } from 'node:fs';3import path from 'node:path';45// Monorepo: a single `.env` lives at the repository root; Next only reads the app directory.6for (const candidate of [path.resolve(process.cwd(), '../../.env'), path.resolve(process.cwd(), '.env')]) {7  if (existsSync(candidate)) {8    try {9      process.loadEnvFile(candidate);10    } catch {11      /* ignore malformed env */12    }13  }14}1516// Dev: FastAPI on :8331 (see repo .env). Production sets API_URL=http://127.0.0.1:8321 in the mld manifest.17const API_URL = (process.env.API_URL ?? 'http://127.0.0.1:8331').replace(/\/$/, '');1819const nextConfig: NextConfig = {20  reactStrictMode: true,21  poweredByHeader: false,22  allowedDevOrigins: ['127.0.0.1', 'localhost'],23  outputFileTracingRoot: path.resolve(__dirname, '../..'),24  experimental: {25    optimizePackageImports: ['lucide-react'],26  },27  // Browser-side fetches go to the same origin; the FastAPI service is loopback-only.28  async rewrites() {29    return [30      { source: '/api/v1/:path*', destination: `${API_URL}/api/v1/:path*` },31      { source: '/health', destination: `${API_URL}/health` },32    ];33  },34  async headers() {35    const PUBLIC_CACHE = { key: 'Cache-Control', value: 'public, s-maxage=300, stale-while-revalidate=3600' };36    const NO_STORE = { key: 'Cache-Control', value: 'private, no-store' };37    return [38      {39        source: '/(.*)',40        headers: [41          { key: 'X-Content-Type-Options', value: 'nosniff' },42          { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },43          { key: 'X-Frame-Options', value: 'SAMEORIGIN' },44          { key: 'Permissions-Policy', value: 'camera=(), microphone=(), geolocation=()' },45          { key: 'Strict-Transport-Security', value: 'max-age=31536000; includeSubDomains' },46        ],47      },48      { source: '/models/:path*', headers: [PUBLIC_CACHE] },49      { source: '/companies/:path*', headers: [PUBLIC_CACHE] },50      { source: '/papers/:path*', headers: [PUBLIC_CACHE] },51      { source: '/providers/:path*', headers: [PUBLIC_CACHE] },52      { source: '/benchmarks/:path*', headers: [PUBLIC_CACHE] },53      { source: '/hardware/:path*', headers: [PUBLIC_CACHE] },54      { source: '/api/:path*', headers: [NO_STORE] },55      { source: '/admin/:path*', headers: [NO_STORE] },56    ];57  },58};5960export default nextConfig;61
Files · c509d7e03d5aed8bc61fb24bc1c8bb3de1f4b9e2
Menu

Theme