import { NextResponse } from 'next/server';
export const dynamic = 'force-dynamic';
interface SitemapIndex {
langCode: string;
filename: string;
}
interface SitemapEntry {
targetType: string;
page: number;
langCode: string;
filename: string;
recordCount: number;
}
interface SitemapApiResponse {
indexes: SitemapIndex[];
totalFiles: number;
sitemaps: SitemapEntry[];
}
export async function GET() {
const gatewayUrl = process.env.PUBLIC_GATEWAY_URL || '';
try {
const res = await fetch(`${gatewayUrl}seo-provider/sitemap`);
if (!res.ok) {
return new NextResponse(null, { status: res.status });
}
const data: SitemapApiResponse = await res.json();
const locs = data.indexes
.map((index) => ` ${index.filename}`)
.join('\n');
const xml = `
${locs}
`;
return new NextResponse(xml, {
headers: { 'Content-Type': 'application/xml' }
});
} catch {
return new NextResponse(null, { status: 500 });
}
}