diff --git a/frontend/app/api/city/[name]/summary/route.ts b/frontend/app/api/city/[name]/summary/route.ts new file mode 100644 index 00000000..77781abf --- /dev/null +++ b/frontend/app/api/city/[name]/summary/route.ts @@ -0,0 +1,40 @@ +import { NextRequest, NextResponse } from "next/server"; + +const API_BASE = process.env.POLYWEATHER_API_BASE_URL; + +export async function GET( + req: NextRequest, + context: { params: Promise<{ name: string }> }, +) { + if (!API_BASE) { + return NextResponse.json( + { error: "POLYWEATHER_API_BASE_URL is not configured" }, + { status: 500 }, + ); + } + + const { name } = await context.params; + const forceRefresh = req.nextUrl.searchParams.get("force_refresh") ?? "false"; + const url = `${API_BASE}/api/city/${encodeURIComponent(name)}/summary?force_refresh=${forceRefresh}`; + + try { + const res = await fetch(url, { + headers: { Accept: "application/json" }, + cache: "no-store", + }); + if (!res.ok) { + const raw = await res.text(); + return NextResponse.json( + { error: `Backend returned ${res.status}`, detail: raw.slice(0, 300) }, + { status: 502 }, + ); + } + const data = await res.json(); + return NextResponse.json(data); + } catch (error) { + return NextResponse.json( + { error: "Failed to fetch city summary", detail: String(error) }, + { status: 500 }, + ); + } +} diff --git a/frontend/app/layout.tsx b/frontend/app/layout.tsx index f90f487a..4ed82a59 100644 --- a/frontend/app/layout.tsx +++ b/frontend/app/layout.tsx @@ -13,6 +13,18 @@ export default function RootLayout({ }: Readonly<{ children: React.ReactNode }>) { return ( + + + + + + {children} diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index 351dd79b..bac0ba32 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -1,12 +1,12 @@ -export default function HomePage() { - return ( -
-