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.
This commit is contained in:
2026-07-23 09:46:28 -04:00
parent 8ae42d32bd
commit e9aa987b94
4 changed files with 287 additions and 28 deletions

View File

@@ -1,35 +1,21 @@
/**
* 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 sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.freno.me</loc>
<lastmod>${new Date().toISOString()}</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://www.freno.me/blog</loc>
<lastmod>${new Date().toISOString()}</lastmod>
<changefreq>daily</changefreq>
<priority>0.9</priority>
</url>
<url>
<loc>https://www.freno.me/contact</loc>
<lastmod>${new Date().toISOString()}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://www.freno.me/login</loc>
<lastmod>${new Date().toISOString()}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
</urlset>`;
const site = getSiteFromEvent(event);
const entries = SITEMAP_ROUTES[site.id] ?? [];
const xml = generateSitemap(site, entries);
return new Response(sitemap, {
return new Response(xml, {
headers: {
"Content-Type": "application/xml",
"Cache-Control": "public, max-age=3600"