Refactor code structure for improved readability and maintainability

This commit is contained in:
hamed
2026-07-06 15:10:19 +03:30
parent beb050aee2
commit df7fbb7530
12 changed files with 7810 additions and 4041 deletions
+7 -1
View File
@@ -4,6 +4,11 @@ import citiesData from '@/data/city.json';
import statesData from '@/data/state.json';
import { isRootCity } from '@/lib/rootCity';
// sitemap باید در زمان اجرا (per-request) روی سرور production تولید شود، نه در build.
// در build کانتینر به API دسترسی شبکه ندارد → fetch failed. force-dynamic این را قطعی می‌کند.
export const dynamic = 'force-dynamic';
export const revalidate = 3600;
const MAIN_DOMAIN = 'nobat724.com';
const API_URL = process.env.NEXT_PUBLIC_API_URL;
const PAGE_LIMIT = 500;
@@ -65,6 +70,7 @@ async function fetchAllPages(path, extraParams = {}) {
});
const res = await fetch(`${API_URL}${path}?${search.toString()}`, {
next: { revalidate: 3600 },
signal: AbortSignal.timeout(8000),
});
if (!res.ok) break;
const json = await res.json();
@@ -76,7 +82,7 @@ async function fetchAllPages(path, extraParams = {}) {
if (items.length < PAGE_LIMIT || (total && results.length >= Number(total))) break;
}
} catch (error) {
console.error(`Error fetching sitemap data from ${path}:`, error);
console.error(`[sitemap] failed to fetch ${path} (page skipped):`, error?.message || error);
}
return results;
}