/** * Runtime proxy for the sitemap family → the FastAPI backend. * * Like the /api/* proxy, this reads FASTAPI_URL at request time rather than * baking the backend host into the build, so one image works in every * environment. robots.ts points crawlers at /sitemap.xml, which is the index; * the index names children under /sitemaps/, which land on the same proxy. */ import { NextResponse } from 'next/server'; function backendOrigin(): string { const base = process.env.FASTAPI_URL || process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000/api'; return base.replace(/\/api$/, ''); } export async function proxySitemap(path: string): Promise { let upstream: Response; try { upstream = await fetch(`${backendOrigin()}${path}`, { cache: 'no-store' }); } catch { return new NextResponse('Sitemap temporarily unavailable', { status: 502 }); } const body = await upstream.text(); return new NextResponse(body, { status: upstream.status, headers: { 'content-type': upstream.headers.get('content-type') || 'application/xml' }, }); }