36 lines
1003 B
TypeScript
36 lines
1003 B
TypeScript
import type { Metadata } from "next";
|
|
import HomeClient from "./HomeClient";
|
|
import { getPageMetadata } from "../lib/seo";
|
|
|
|
export async function generateMetadata(): Promise<Metadata> {
|
|
return getPageMetadata('home', {
|
|
canonicalPath: '/',
|
|
});
|
|
}
|
|
|
|
import { HomeApiResponse } from "../lib/types";
|
|
|
|
async function getHomeData(): Promise<HomeApiResponse | null> {
|
|
try {
|
|
const apiUrl = process.env.INTERNAL_API_URL || process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4001/api';
|
|
const res = await fetch(`${apiUrl}/home`, {
|
|
next: { revalidate: 3600, tags: ['home-data'] },
|
|
});
|
|
|
|
if (!res.ok) {
|
|
console.error(`Failed to fetch home data: ${res.status} ${res.statusText}`);
|
|
return null;
|
|
}
|
|
|
|
return await res.json();
|
|
} catch (error) {
|
|
console.error('Error fetching home data on server:', error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export default async function Home() {
|
|
const initialData = await getHomeData();
|
|
return <HomeClient initialData={initialData} />;
|
|
}
|