feat: establish public SEO foundation
CI / backend-and-migrations (push) Canceled after 0s
CI / astro-build (push) Canceled after 0s
CI / compose-e2e (push) Canceled after 0s

This commit is contained in:
ik
2026-09-07 13:29:13 +07:00
parent 9275799ce7
commit 494a37ce8f
14 changed files with 160 additions and 12 deletions
+19
View File
@@ -0,0 +1,19 @@
import type { APIRoute } from "astro";
import { api, type Activity } from "../lib/api";
const escapeXml = (value: string) => value.replace(/[<>&'\"]/g, character => ({ "<": "&lt;", ">": "&gt;", "&": "&amp;", "'": "&apos;", '"': "&quot;" })[character] ?? character);
export const GET: APIRoute = async ({ site }) => {
const origin = site?.origin ?? import.meta.env.PUBLIC_SITE_URL ?? "https://rf4spotter.ru";
const paths = new Set(["/", "/records", "/report", "/rules", "/privacy"]);
try {
const activity = await api<Activity[]>("/api/v1/activity?hours=72&limit=100");
activity.forEach(item => paths.add(`/spots/${item.spot_id}`));
} catch {
// A temporary API outage must not make the static part of the sitemap unavailable.
}
const urls = [...paths].map(path => `<url><loc>${escapeXml(new URL(path, origin).toString())}</loc></url>`).join("");
return new Response(`<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${urls}</urlset>`, {
headers: { "Content-Type": "application/xml; charset=utf-8", "Cache-Control": "public, max-age=1800" },
});
};