import type { NextConfig } from "next"; /** * Ingest API backend (same LXC, port 3041). * In Docker Compose the service name is "ingest-api"; on bare-metal it is localhost. */ const INGEST_API_URL = process.env.INGEST_API_URL || "http://127.0.0.1:3041"; /** * Admin/mutation API backend (same LXC, port 3200). * Proxies hub-only mutation endpoints (resolve-fixed-patterns, etc.) so they are * reachable via the public errors.bitreport.pt hostname without a separate FQDN. * BIT-25072: resolve-fixed-patterns is hub-only; CRM error-loop calls this via HTTPS. */ const ADMIN_API_URL = process.env.ERROR_REPORTING_ADMIN_API_BASE || "http://127.0.0.1:3200"; const nextConfig: NextConfig = { output: "standalone", reactStrictMode: true, async rewrites() { return [ { source: "/health", destination: `${INGEST_API_URL}/health` }, // BIT-31442: the recent-errors handler (api/src/routes/public/recentErrors.ts) // registers the /v1/paperclip/recent-errors alias on the admin API (port 3200), // not on ingest-api. The generic /v1/* rule below would otherwise send it to // ingest-api (port 3041), which has no such route and returns 404. This more // specific rule must come first; Next.js evaluates rewrites in order. { source: "/v1/paperclip/:path*", destination: `${ADMIN_API_URL}/v1/paperclip/:path*`, }, { source: "/v1/:path*", destination: `${INGEST_API_URL}/v1/:path*` }, { source: "/api/error-monitoring/:path*", destination: `${ADMIN_API_URL}/api/error-monitoring/:path*`, }, ]; }, }; export default nextConfig;