combine the lib/fetnewsdata.tsx to app/api/news/[id]/page.tsx
This commit is contained in:
parent
e8e90d84cc
commit
07a66489d1
2 changed files with 19 additions and 7 deletions
|
@ -1,8 +1,15 @@
|
|||
import { fetchNewsData } from "../../../lib/fetchNewsData";
|
||||
import NewsDetail from "../../../components/NewsDetail";
|
||||
|
||||
async function getNewsData(id: string) {
|
||||
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/news/${id}`, { next: { revalidate: 60 } });
|
||||
if (!res.ok) {
|
||||
throw new Error("Failed to fetch news");
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export default async function NewsPage({ params }: { params: { id: string } }) {
|
||||
const newsData = await fetchNewsData(params.id);
|
||||
const newsData = await getNewsData(params.id);
|
||||
|
||||
if (!newsData) {
|
||||
return <div className="text-center text-red-500">News not found or failed to load</div>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue