// app/api/n8n/status/route.ts import { NextResponse } from "next/server"; // Cache für 30 Sekunden, damit wir n8n nicht zuspammen export const revalidate = 30; export async function GET() { try { // Rufe den n8n Webhook auf const res = await fetch(`${process.env.N8N_WEBHOOK_URL}/denshooter-71242/status`, { method: "GET", headers: { "Content-Type": "application/json", }, // Cache-Optionen für Next.js next: { revalidate: 30 } }); if (!res.ok) { throw new Error(`n8n error: ${res.status}`); } const data = await res.json(); // n8n gibt oft ein Array zurück: [{...}]. Wir wollen nur das Objekt. const statusData = Array.isArray(data) ? data[0] : data; return NextResponse.json(statusData); } catch (error) { console.error("Error fetching n8n status:", error); // Leeres Fallback-Objekt, damit die Seite nicht abstürzt return NextResponse.json({ status: { text: "offline", color: "gray" }, music: null, gaming: null, coding: null }); } }