Files
ipv6-sims/api/headerApi.ts
T
2026-05-11 16:24:14 +07:00

40 lines
965 B
TypeScript

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[];
}