refactor(sitemap): remove static routes from sitemap generation and handle errors more gracefully
This commit is contained in:
@@ -17,24 +17,6 @@ interface SitemapRoute {
|
|||||||
const baseUrl = "https://dki.one";
|
const baseUrl = "https://dki.one";
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
console.log("Generating sitemap...");
|
|
||||||
|
|
||||||
const staticRoutes: SitemapRoute[] = [
|
|
||||||
{url: `${baseUrl}/`, lastModified: new Date().toISOString(), changeFrequency: "weekly", priority: 1.0},
|
|
||||||
{
|
|
||||||
url: `${baseUrl}/privacy-policy`,
|
|
||||||
lastModified: new Date().toISOString(),
|
|
||||||
changeFrequency: "yearly",
|
|
||||||
priority: 0.3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: `${baseUrl}/legal-notice`,
|
|
||||||
lastModified: new Date().toISOString(),
|
|
||||||
changeFrequency: "yearly",
|
|
||||||
priority: 0.3
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${baseUrl}/api/sitemap`);
|
const response = await fetch(`${baseUrl}/api/sitemap`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -42,14 +24,14 @@ export async function GET() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dynamicRoutes = (await response.json()) as SitemapRoute[];
|
const dynamicRoutes = (await response.json()) as SitemapRoute[];
|
||||||
const sitemap = [...staticRoutes, ...dynamicRoutes];
|
const sitemap = [...dynamicRoutes];
|
||||||
|
|
||||||
return new NextResponse(generateXml(sitemap), {
|
return new NextResponse(generateXml(sitemap), {
|
||||||
headers: {"Content-Type": "application/xml"},
|
headers: {"Content-Type": "application/xml"},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching dynamic routes, using fallback:", error);
|
console.error("Error fetching dynamic routes, using fallback:", error);
|
||||||
return new NextResponse(generateXml(staticRoutes), {
|
return new NextResponse(generateXml([]), {
|
||||||
headers: {"Content-Type": "application/xml"},
|
headers: {"Content-Type": "application/xml"},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user