seo: always serve sitemap.xml even if DB unavailable

Co-authored-by: dennis <dennis@konkol.net>
This commit is contained in:
Cursor Agent
2026-01-15 10:12:38 +00:00
parent d60f875793
commit b90a3d589c
2 changed files with 7 additions and 3 deletions

View File

@@ -58,11 +58,15 @@ export async function getSitemapEntries(): Promise<SitemapEntry[]> {
orderBy: { updatedAt: "desc" },
});
} catch (error) {
// If DB isn't ready/migrated yet, still serve a valid sitemap for static pages.
// If DB isn't ready/migrated/reachable yet, still serve a valid sitemap for static pages.
if (process.env.NODE_ENV === "development") {
console.warn("Sitemap: failed to load projects; serving static entries only.", error);
}
if (error instanceof PrismaClientKnownRequestError && (error.code === "P2021" || error.code === "P2022")) {
return staticEntries;
}
throw error;
// Also fail soft on connection/init errors in dev/staging (keeps sitemap valid for crawlers)
return staticEntries;
}
const projectEntries: SitemapEntry[] = projects.flatMap((p) => {