full upgrade to dev
This commit is contained in:
@@ -7,14 +7,17 @@ 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",
|
||||
// Add timestamp to query to bypass Cloudflare cache
|
||||
const res = await fetch(
|
||||
`${process.env.N8N_WEBHOOK_URL}/webhook/denshooter-71242/status?t=${Date.now()}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
next: { revalidate: 30 },
|
||||
},
|
||||
// Cache-Optionen für Next.js
|
||||
next: { revalidate: 30 }
|
||||
});
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`n8n error: ${res.status}`);
|
||||
@@ -25,6 +28,19 @@ export async function GET() {
|
||||
// n8n gibt oft ein Array zurück: [{...}]. Wir wollen nur das Objekt.
|
||||
const statusData = Array.isArray(data) ? data[0] : data;
|
||||
|
||||
// Safety check: if statusData is still undefined/null (e.g. empty array), use fallback
|
||||
if (!statusData) {
|
||||
throw new Error("Empty data received from n8n");
|
||||
}
|
||||
|
||||
// Ensure coding object has proper structure
|
||||
if (statusData.coding && typeof statusData.coding === "object") {
|
||||
// Already properly formatted from n8n
|
||||
} else if (statusData.coding === null || statusData.coding === undefined) {
|
||||
// No coding data - keep as null
|
||||
statusData.coding = null;
|
||||
}
|
||||
|
||||
return NextResponse.json(statusData);
|
||||
} catch (error) {
|
||||
console.error("Error fetching n8n status:", error);
|
||||
@@ -33,7 +49,7 @@ export async function GET() {
|
||||
status: { text: "offline", color: "gray" },
|
||||
music: null,
|
||||
gaming: null,
|
||||
coding: null
|
||||
coding: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user