From 7ce607fa9b39e76678af47c948564bc46d3cc762 Mon Sep 17 00:00:00 2001 From: Adrian Bonpin Date: Mon, 25 May 2026 21:47:08 +0800 Subject: [PATCH] fix: add sitemap index route at /sitemap.xml for Next.js 16 generateSitemaps --- app/sitemap.xml/route.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/sitemap.xml/route.ts diff --git a/app/sitemap.xml/route.ts b/app/sitemap.xml/route.ts new file mode 100644 index 0000000..262ef86 --- /dev/null +++ b/app/sitemap.xml/route.ts @@ -0,0 +1,27 @@ +import { generateSitemaps } from "@/app/sitemap" +import { getBaseUrl } from "@/lib/sitemap-utils" + +export const revalidate = 3600 + +export async function GET() { + const baseUrl = getBaseUrl() + const sitemaps = await generateSitemaps() + + const entries = sitemaps + .map(({ id }) => ` \n ${baseUrl}/sitemap/${id}.xml\n `) + .join("\n") + + const xml = [ + ``, + ``, + entries, + ``, + ].join("\n") + + return new Response(xml, { + headers: { + "Content-Type": "application/xml", + "Cache-Control": "public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400", + }, + }) +} \ No newline at end of file