Skip to content

Commit

Permalink
feat (uvindex): new api
Browse files Browse the repository at this point in the history
  • Loading branch information
IFTE-13 committed Dec 31, 2024
1 parent a47aad0 commit 3dfafde
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/api/uvindex/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 Getting Uv Data");

return new Response("Error getting Uv Data", { status: 500 });
}
}

0 comments on commit 3dfafde

Please sign in to comment.