Archived
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
import type { SiteSettings } from "@/contexts/SiteSettingsContext";
|
|
import { API_BASE } from "@/lib/api";
|
|
|
|
/**
|
|
* Server-side settings fetch, shared by the root layout (generateMetadata and
|
|
* RootLayout) and server pages that need branding, e.g. the event page's organizer.
|
|
* Every caller uses the identical URL + options, so Next's per-request fetch
|
|
* memoization dedupes them into a single network call. Degrades to `{}`
|
|
* (static defaults everywhere downstream) if the backend is unreachable at
|
|
* request time — intentional, not a bug: branding just isn't critical enough
|
|
* to fail the whole page render over.
|
|
*/
|
|
export async function getServerSettings(): Promise<SiteSettings> {
|
|
// No API base configured: a relative fetch never settles during prerender and
|
|
// would time out every page, so skip straight to the defaults.
|
|
if (!API_BASE) return {};
|
|
try {
|
|
const res = await fetch(`${API_BASE}/api/v2/settings`, { next: { revalidate: 60 } });
|
|
if (!res.ok) return {};
|
|
return (await res.json())?.data || {};
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|