Files
logbuch/app/api/wetter/route.ts
T

17 lines
692 B
TypeScript

import { NextResponse } from 'next/server';
import { getSession } from '@/lib/session';
export async function GET() {
const session = await getSession();
if (!session) return NextResponse.json({ error: 'Nicht angemeldet' }, { status: 401 });
const res = await fetch('https://stwwetter.fuerst-stuttgart.de/api/weather/latest', { cache: 'no-store' });
if (!res.ok) return NextResponse.json({ error: 'Wetterdaten nicht verfügbar' }, { status: 502 });
const data = await res.json();
const temp = Math.round(data.temperature * 10) / 10;
const feuchte = Math.round(data.humidity);
const druck = Math.round(data.pressure);
return NextResponse.json({ temp, feuchte, druck });
}