feat: add global weather support
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m54s
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m54s
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { fetchServerForecast, parseForecastCoordinate } from "@/lib/server-forecast";
|
||||
import type { WeatherRegion } from "@/types/weather-region";
|
||||
|
||||
function parseRegion(value: string | null): WeatherRegion {
|
||||
return value === "GLOBAL" ? "GLOBAL" : "PL";
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const latitude = parseForecastCoordinate(searchParams.get("latitude"), -90, 90);
|
||||
const longitude = parseForecastCoordinate(searchParams.get("longitude"), -180, 180);
|
||||
const region = parseRegion(searchParams.get("region"));
|
||||
if (latitude === null || longitude === null) {
|
||||
return NextResponse.json({ error: "Invalid coordinates." }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
return NextResponse.json(await fetchServerForecast(latitude, longitude), {
|
||||
return NextResponse.json(await fetchServerForecast(latitude, longitude, region), {
|
||||
headers: { "Cache-Control": "public, s-maxage=900, stale-while-revalidate=1800" },
|
||||
});
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user