forked from UKSOURCE/ipv6
init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { HeaderData, HeaderMenuItem } from '@/types/header';
|
||||
|
||||
const CMS_API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001';
|
||||
|
||||
export async function fetchHeaderData(): Promise<HeaderData> {
|
||||
const res = await fetch(`${CMS_API_URL}/api/header`, {
|
||||
next: { revalidate: 60 },
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`Failed to fetch header: ${res.status}`);
|
||||
}
|
||||
|
||||
const json = await res.json();
|
||||
|
||||
if (!json.success) {
|
||||
throw new Error(json.message || 'Header API error');
|
||||
}
|
||||
|
||||
return json.data as HeaderData;
|
||||
}
|
||||
|
||||
export async function fetchHeaderMenu(): Promise<HeaderMenuItem[]> {
|
||||
const res = await fetch(`${CMS_API_URL}/api/header-menu`, {
|
||||
next: { revalidate: 60 },
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`Failed to fetch menu: ${res.status}`);
|
||||
}
|
||||
|
||||
const json = await res.json();
|
||||
|
||||
if (!json.success) {
|
||||
throw new Error(json.message || 'Menu API error');
|
||||
}
|
||||
|
||||
return json.data as HeaderMenuItem[];
|
||||
}
|
||||
Reference in New Issue
Block a user