local-weather/app/api/forecast/route.ts
ChrQR 31f633e982
Some checks failed
Docker Build & Publish / Build Docker (push) Failing after 51s
Implemented api for the weather call.
2024-05-18 01:50:05 +02:00

17 lines
990 B
TypeScript

import { Forecast } from "@/types/types";
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const lat = searchParams.get("lat");
const lng = searchParams.get("lng");
const res = await fetch(
`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lng}&current=temperature_2m,apparent_temperature,is_day,precipitation,rain,showers,snowfall,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m&hourly=temperature_2m,apparent_temperature,precipitation_probability,precipitation,weather_code,wind_speed_10m,is_day&daily=weather_code,temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,sunrise,sunset,daylight_duration,sunshine_duration,uv_index_max,precipitation_sum,precipitation_hours,wind_speed_10m_max&timezone=auto`
);
if (!res.ok) {
throw new Error(`Failed to fetch the weather data`);
}
const data: Forecast = await res.json();
return Response.json({ data });
}