Files
smart-home-tablet/app/api/weather/route.ts
Cosmo 9044869fa4
All checks were successful
Deploy to Coolify / deploy (push) Successful in 44s
feat: initial smart home dashboard
- Next.js 14 + TypeScript + Tailwind CSS
- Glassmorphism design with ambient orbs
- Cards: Light x2, Temperature, AirPurifier, Tasks, Weather, Savings
- Home Assistant integration (demo mode if no token)
- Vikunja tasks API
- Pulse savings API
- wttr.in weather
- Framer Motion animations
- Dark/light theme toggle
- Bottom navigation
- Dockerfile for deployment
2026-04-22 10:00:41 +00:00

51 lines
1.3 KiB
TypeScript

import { NextResponse } from "next/server";
export async function GET() {
try {
const res = await fetch(
"https://wttr.in/Saint+Petersburg?format=j1",
{
next: { revalidate: 600 },
headers: { "User-Agent": "SmartHomeDashboard/1.0" },
}
);
if (!res.ok) throw new Error("Weather fetch failed");
const data = await res.json();
const current = data.current_condition[0];
const days = data.weather.slice(0, 3).map((day: any) => {
const desc = day.hourly[4]?.weatherDesc?.[0]?.value || "";
return {
date: day.date,
maxTemp: day.maxtempC,
minTemp: day.mintempC,
desc,
weatherCode: day.hourly[4]?.weatherCode || "113",
};
});
return NextResponse.json({
temp: current.temp_C,
feelsLike: current.FeelsLikeC,
humidity: current.humidity,
desc: current.weatherDesc[0]?.value || "",
weatherCode: current.weatherCode,
windSpeed: current.windspeedKmph,
forecast: days,
});
} catch (e) {
return NextResponse.json(
{
temp: "—",
feelsLike: "—",
humidity: "—",
desc: "Нет данных",
weatherCode: "113",
windSpeed: "—",
forecast: [],
},
{ status: 200 }
);
}
}