1import type { NextConfig } from 'next';2import { existsSync } from 'node:fs';3import path from 'node:path';45// Monorepo: the 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}1516const nextConfig: NextConfig = {17 reactStrictMode: true,18 poweredByHeader: false,19 agentRules: false,20 // Workspace packages are consumed as TypeScript sources.21 transpilePackages: ['@rareindex/shared', '@rareindex/database', '@rareindex/taxonomy', '@rareindex/connectors', '@rareindex/ai', '@rareindex/notify'],22 serverExternalPackages: ['postgres', 'pino', 'cheerio', 'pg-boss', '@anthropic-ai/sdk', 'openai'],23 // Public API: /api/v1/* is proxied to the Fastify service (apps/api) so one public host serves web + API.24 async rewrites() {25 const api = process.env.RI_API_URL ?? `http://127.0.0.1:${process.env.API_PORT ?? 8211}`;26 return [{ source: '/api/v1/:path*', destination: `${api}/v1/:path*` }];27 },28 images: {29 remotePatterns: [{ protocol: 'https', hostname: '**' }],30 formats: ['image/avif', 'image/webp'],31 },32 experimental: {33 optimizePackageImports: ['lucide-react'],34 // Workspace packages use NodeNext-style `./file.js` imports that resolve to .ts sources.35 // Turbopack does not rewrite these outside the app root, so the app is built with webpack36 // (`next dev/build --webpack`) where extensionAlias handles the mapping.37 extensionAlias: { '.js': ['.ts', '.tsx', '.js'], '.mjs': ['.mts', '.mjs'] },38 },39 outputFileTracingRoot: path.resolve(__dirname, '../..'),40 async headers() {41 return [42 {43 source: '/(.*)',44 headers: [45 { key: 'X-Content-Type-Options', value: 'nosniff' },46 { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },47 { key: 'X-Frame-Options', value: 'SAMEORIGIN' },48 { key: 'Permissions-Policy', value: 'camera=(self), microphone=(), geolocation=()' },49 ],50 },51 ];52 },53};5455export default nextConfig;56