feat: implement initial home page with dynamic content, API, and dedicated components.

This commit is contained in:
Wini_Fy
2026-02-05 15:56:06 +07:00
parent 857d250435
commit 11f435378f
8 changed files with 189 additions and 102 deletions

43
api/homeApi.ts Normal file
View File

@@ -0,0 +1,43 @@
/**
* Lấy API URL từ environment variable
*/
const getApiUrl = (): string => {
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
if (!apiUrl) {
console.warn('NEXT_PUBLIC_API_URL is not set. Using default http://localhost:3001');
return 'http://localhost:3001';
}
return apiUrl;
};
/**
* Fetch home page data từ API
* @returns Promise<any>
* @throws Error nếu fetch thất bại
*/
export const fetchHomeData = async (): Promise<any> => {
const apiUrl = getApiUrl();
const url = `${apiUrl}/api/home`;
try {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
cache: 'no-store',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching home data:', error);
return null; // Trả về null để fallback sang dữ liệu local
}
};