39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
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 ||
|
|
(process.env.NODE_ENV === 'production' ? 'https://api.canina.ir/api' : 'http://127.0.0.1:4400/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} />;
|
|
}
|