Refactor code structure for improved readability and maintainability
This commit is contained in:
+7
-1
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user