diff --git a/weather_app/app/api/dailyForecast/route.ts b/weather_app/app/api/dailyForecast/route.ts new file mode 100644 index 0000000..967d2fa --- /dev/null +++ b/weather_app/app/api/dailyForecast/route.ts @@ -0,0 +1,19 @@ +import { NextRequest, NextResponse } from "next/server"; + +export async function GET(req: NextRequest){ + try { + const searchParams = req.nextUrl.searchParams + const lat = searchParams.get("lat"); + const lon = searchParams.get("lon"); + const apiKey = process.env.OPENWEATHERMAP_API_KEY; + const url = `http://api.openweathermap.org/data/2.5/forecast?lat=${lat}&lon=${lon}&appid=${apiKey}` + const res = await fetch(url, { + next: {revalidate: 3600}, + }) + const data = await res.json(); + return NextResponse.json(data) + + } catch (error) { + return new Response('Error', {status: 500}); + } +} \ No newline at end of file diff --git a/weather_app/app/api/geoCoordinate/route.ts b/weather_app/app/api/geoCoordinate/route.ts new file mode 100644 index 0000000..9f73f76 --- /dev/null +++ b/weather_app/app/api/geoCoordinate/route.ts @@ -0,0 +1,17 @@ +import axios from "axios"; +import { NextRequest, NextResponse } from "next/server"; + +export async function GET(req: NextRequest){ + try { + const apiKey = process.env.OPENWEATHERMAP_API_KEY; + const searchParams = req.nextUrl.searchParams; + const city = searchParams.get('search'); + const url = `http://api.openweathermap.org/geo/1.0/direct?q=${city}&limit=5&appid=${apiKey}` + const res = await axios.get(url); + return NextResponse.json(res.data) + + } catch (error) { + console.log(error) + return new Response('Error', {status: 500}); + } +} \ No newline at end of file diff --git a/weather_app/app/api/pollution/route.ts b/weather_app/app/api/pollution/route.ts new file mode 100644 index 0000000..6f24b5b --- /dev/null +++ b/weather_app/app/api/pollution/route.ts @@ -0,0 +1,17 @@ +import axios from "axios"; +import { NextRequest, NextResponse } from "next/server"; + +export async function GET(req: NextRequest) { + try { + const searchParams = req.nextUrl.searchParams + const lat = searchParams.get("lat"); + const lon = searchParams.get("lon"); + const apiKey = process.env.OPENWEATHERMAP_API_KEY; + const url = `http://api.openweathermap.org/data/2.5/air_pollution?lat=${lat}&lon=${lon}&appid=${apiKey}` + const res = await axios.get(url) + return NextResponse.json(res.data); + } catch (error) { + console.log(error) + return new Response('Error', {status: 500}); + } +} \ No newline at end of file diff --git a/weather_app/app/api/uvIndex/route.ts b/weather_app/app/api/uvIndex/route.ts new file mode 100644 index 0000000..39258b4 --- /dev/null +++ b/weather_app/app/api/uvIndex/route.ts @@ -0,0 +1,19 @@ +import { NextRequest, NextResponse } from "next/server"; + +export async function GET(req: NextRequest) { + try { + const searchParams = req.nextUrl.searchParams + const lat = searchParams.get("lat"); + const lon = searchParams.get("lon"); + const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&daily=uv_index_max,uv_index_clear_sky_max&timezone=auto&forecast_days=1` + const res = await fetch(url, { + next: {revalidate: 900}, + }); + const UVData = await res.json() + return NextResponse.json(UVData) + + } catch (error) { + console.log(error) + return new Response('Error', {status: 500}); + } +} \ No newline at end of file diff --git a/weather_app/app/api/weather/route.ts b/weather_app/app/api/weather/route.ts new file mode 100644 index 0000000..dc5f0b4 --- /dev/null +++ b/weather_app/app/api/weather/route.ts @@ -0,0 +1,19 @@ +import axios from "axios"; +import { NextRequest, NextResponse } from "next/server"; + +export async function GET(req: NextRequest){ + try { + const searchParams = req.nextUrl.searchParams; + const lat = searchParams.get("lat"); + const lon = searchParams.get("lon"); + const apiKey = process.env.OPENWEATHERMAP_API_KEY; + const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${apiKey}` + const res = await axios.get(url); + return NextResponse.json(res.data); + + + } catch (error){ + console.log(error) + return new Response('Error', {status: 500}); + } +} \ No newline at end of file