/** @type {import('next').NextConfig} */ // Normalise the backend base URL so a value supplied without a scheme (e.g. // "my-app.hf.space") or with a trailing slash can't break the rewrite, which // requires a destination starting with "/", "http://", or "https://". function normalizeApiBase(raw) { const v = (raw || "").trim(); if (!v) return "http://localhost:8000"; const withScheme = /^https?:\/\//i.test(v) ? v : `https://${v}`; return withScheme.replace(/\/+$/, ""); } const API = normalizeApiBase(process.env.NEXT_PUBLIC_API_BASE); const nextConfig = { reactStrictMode: true, async rewrites() { // Proxy API + page images to the FastAPI backend during dev so the // browser hits a single origin (no CORS surprises for image tags). return [{ source: "/api/:path*", destination: `${API}/api/:path*` }]; }, }; export default nextConfig;