Files
freno-dev/src/routes/sitemap.xml.ts
Michael Freno e9aa987b94 feat: generate per-subdomain sitemaps based on Host header
Refactor sitemap.xml route to read the Host header, determine the active
site, and produce a sitemap scoped to that site's routes with canonical
URLs. Extracts route definitions and XML generation into shared modules.
2026-07-23 09:46:28 -04:00

25 lines
785 B
TypeScript

/**
* Host-aware sitemap.xml route handler (task 03).
*
* Reads the `Host` header to determine the active site, then generates a
* sitemap scoped to that site's routes with canonical URLs from the
* corresponding domain.
*/
import { APIEvent } from "@solidjs/start/server";
import { getSiteFromEvent } from "~/server/site-context-server";
import { SITEMAP_ROUTES } from "~/lib/sitemap-routes";
import { generateSitemap } from "~/lib/sitemap-generate";
export async function GET(event: APIEvent) {
const site = getSiteFromEvent(event);
const entries = SITEMAP_ROUTES[site.id] ?? [];
const xml = generateSitemap(site, entries);
return new Response(xml, {
headers: {
"Content-Type": "application/xml",
"Cache-Control": "public, max-age=3600"
}
});
}