Files
web/apps/scandic-web/app/sitemap/route.ts
Erik Tiekstra ca93046aad feat/SW-550 sitemap route
* feat(SW-550): Added rewrites to handle sitemap paths

* feat(SW-550): Added sitemap-index generation

* feat(SW-550): Added sitemap xml file generation

* feat(SW-550): Added feature flag 'HIDE_FOR_NEXT_RELEASE' to sitemap routes


Approved-by: Linus Flood
2025-03-17 07:17:08 +00:00

30 lines
773 B
TypeScript

import { notFound } from "next/navigation"
import { env } from "@/env/server"
import { getLastUpdated, getSitemapIds } from "@/utils/sitemap"
export const dynamic = "force-dynamic"
export async function GET() {
if (env.HIDE_FOR_NEXT_RELEASE) {
notFound()
}
const lastUpdated = await getLastUpdated()
const sitemaps = await getSitemapIds()
const urls = sitemaps.map(
(id) => `<sitemap>
<loc>${env.PUBLIC_URL}/sitemap-${id}.xml</loc>
<lastmod>${lastUpdated}</lastmod>
</sitemap>`
)
const sitemapIndexXML = `<?xml version="1.0" encoding="UTF-8"?>\n<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${urls.join("")}\n</sitemapindex>`
return new Response(sitemapIndexXML, {
headers: { "Content-Type": "text/xml" },
})
}