diff --git a/ui/app/api/news/route.ts b/ui/app/api/news/route.ts new file mode 100644 index 0000000..40cedbc --- /dev/null +++ b/ui/app/api/news/route.ts @@ -0,0 +1,16 @@ +import { NextResponse } from "next/server"; +import fs from "node:fs/promises"; +import path from "node:path"; + +export async function GET() { + try { + const dataDirectory = path.join(process.cwd(), "public", "data"); + const filePath = path.join(dataDirectory, "index.json"); + const fileContents = await fs.readFile(filePath, "utf8"); + const data = JSON.parse(fileContents); + return NextResponse.json(data); + } catch (error) { + console.error("Error reading news data:", error); + return NextResponse.json({ error: "Failed to load news data" }, { status: 500 }); + } +} diff --git a/ui/components/NewsPage.tsx b/ui/components/NewsPage.tsx index 62072c2..b39551b 100644 --- a/ui/components/NewsPage.tsx +++ b/ui/components/NewsPage.tsx @@ -19,9 +19,7 @@ const NewsPage = () => { const fetchNews = async () => { try { console.log("Fetching news..."); - const response = await fetch( - "https://raw.githubusercontent.com/newspedia-crew/newspedia-web/intern-change/public/data/index.json", - ); + const response = await fetch("/api/news"); console.log("Response status:", response.status); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); diff --git a/public/data/1fa9b398-080f-54de-9a4f-3ba386acce11.json b/ui/public/data/1fa9b398-080f-54de-9a4f-3ba386acce11.json similarity index 100% rename from public/data/1fa9b398-080f-54de-9a4f-3ba386acce11.json rename to ui/public/data/1fa9b398-080f-54de-9a4f-3ba386acce11.json diff --git a/public/data/73090b7b-a04e-5c50-ae84-c77f1d7d03a8.json b/ui/public/data/73090b7b-a04e-5c50-ae84-c77f1d7d03a8.json similarity index 100% rename from public/data/73090b7b-a04e-5c50-ae84-c77f1d7d03a8.json rename to ui/public/data/73090b7b-a04e-5c50-ae84-c77f1d7d03a8.json diff --git a/public/data/869d933c-e186-51b0-a225-edc2d338b6fa.json b/ui/public/data/869d933c-e186-51b0-a225-edc2d338b6fa.json similarity index 100% rename from public/data/869d933c-e186-51b0-a225-edc2d338b6fa.json rename to ui/public/data/869d933c-e186-51b0-a225-edc2d338b6fa.json diff --git a/public/data/b84c7962-2971-53de-a99b-3c9e45492c79.json b/ui/public/data/b84c7962-2971-53de-a99b-3c9e45492c79.json similarity index 100% rename from public/data/b84c7962-2971-53de-a99b-3c9e45492c79.json rename to ui/public/data/b84c7962-2971-53de-a99b-3c9e45492c79.json diff --git a/public/data/ed701716-e443-5804-aaa9-99e7e04c33e2.json b/ui/public/data/ed701716-e443-5804-aaa9-99e7e04c33e2.json similarity index 100% rename from public/data/ed701716-e443-5804-aaa9-99e7e04c33e2.json rename to ui/public/data/ed701716-e443-5804-aaa9-99e7e04c33e2.json diff --git a/public/data/fd20973f-54b2-5b15-bf7b-79b5e5515b5c.json b/ui/public/data/fd20973f-54b2-5b15-bf7b-79b5e5515b5c.json similarity index 100% rename from public/data/fd20973f-54b2-5b15-bf7b-79b5e5515b5c.json rename to ui/public/data/fd20973f-54b2-5b15-bf7b-79b5e5515b5c.json diff --git a/public/data/index.json b/ui/public/data/index.json similarity index 100% rename from public/data/index.json rename to ui/public/data/index.json