feat: add global weather support
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m54s

This commit is contained in:
zv
2026-06-14 15:53:34 +02:00
parent d572c9cc53
commit 2182297adc
45 changed files with 739 additions and 212 deletions

View File

@@ -1,4 +1,5 @@
import { NextResponse } from "next/server";
import { getWeatherRegionForCountryCode } from "@/types/weather-region";
const REVERSE_GEOCODING_URL = "https://nominatim.openstreetmap.org/reverse";
const USER_AGENT = "wtr./1.0 (https://git.zvcloud.net/zv/wtr)";
@@ -13,6 +14,8 @@ interface RawReverseLocation {
municipality?: string;
county?: string;
state?: string;
country?: string;
country_code?: string;
};
}
@@ -54,10 +57,17 @@ export async function GET(request: Request) {
?? data.name
?? data.display_name?.split(",")[0]?.trim();
if (!name) return NextResponse.json({ error: "Place name is unavailable." }, { status: 404 });
const countryCode = data.address?.country_code?.toUpperCase() ?? null;
return NextResponse.json({
name,
province: data.address?.state ?? null,
district: data.address?.county ?? null,
country: data.address?.country ?? null,
countryCode,
admin1: data.address?.state ?? null,
admin2: data.address?.county ?? null,
timezone: null,
region: getWeatherRegionForCountryCode(countryCode),
}, {
headers: { "Cache-Control": "public, s-maxage=86400, stale-while-revalidate=604800" },
});