forked from UKSOURCE/hailearning.edu.vn
Add footer API integration
This commit is contained in:
62
api/footerApi.ts
Normal file
62
api/footerApi.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Footer API Functions
|
||||
* Fetch footer data from external API
|
||||
*/
|
||||
|
||||
const getApiUrl = (): string => {
|
||||
return process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001";
|
||||
};
|
||||
|
||||
export interface FooterData {
|
||||
top: {
|
||||
bgImage: string;
|
||||
phone: {
|
||||
display: string;
|
||||
href: string;
|
||||
};
|
||||
address: string;
|
||||
logo: {
|
||||
src: string;
|
||||
alt: string;
|
||||
href: string;
|
||||
};
|
||||
menuLinks: Array<{
|
||||
label: string;
|
||||
href: string;
|
||||
}>;
|
||||
socialLinks: Array<{
|
||||
icon: string;
|
||||
href: string;
|
||||
}>;
|
||||
};
|
||||
bottom: {
|
||||
copyright: {
|
||||
text: string;
|
||||
brand: string;
|
||||
rights: string;
|
||||
};
|
||||
menuLinks: Array<{
|
||||
label: string;
|
||||
href: string;
|
||||
}>;
|
||||
};
|
||||
}
|
||||
|
||||
export const footerApi = {
|
||||
// Get footer data
|
||||
getFooter: async (): Promise<FooterData> => {
|
||||
try {
|
||||
const apiUrl = getApiUrl();
|
||||
const response = await fetch(`${apiUrl}/api/footer`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Error fetching footer data:", error);
|
||||
// Fallback to static data if API fails
|
||||
const fallbackData = await import("../app/components/layout/Footer/footer.json");
|
||||
return fallbackData.default as FooterData;
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user