forked from UKSOURCE/hailearning.edu.vn
feat(about): Implement about API integration and migrate from static JSON
This commit is contained in:
35
api/aboutApi.ts
Normal file
35
api/aboutApi.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* About API Functions
|
||||
* Fetch about us data from external API
|
||||
*/
|
||||
|
||||
const getApiUrl = (): string => {
|
||||
return process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001";
|
||||
};
|
||||
|
||||
import { AboutData } from "../app/about/types";
|
||||
|
||||
export const aboutApi = {
|
||||
// Get about us data
|
||||
getAbout: async (): Promise<AboutData | null> => {
|
||||
try {
|
||||
const apiUrl = getApiUrl();
|
||||
const response = await fetch(`${apiUrl}/api/about`, {
|
||||
cache: 'no-store',
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache',
|
||||
'Pragma': 'no-cache'
|
||||
}
|
||||
});
|
||||
if (!response.ok) {
|
||||
console.error(`HTTP error! status: ${response.status}`);
|
||||
return null;
|
||||
}
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Error fetching about data:", error);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user