import { after } from "next/server"; import { bugsinkFromEnv } from "@peppa/bugsink"; import { processIncidents, receiveBugsinkWebhook } from "@peppa/runner"; import { db } from "@/lib/db"; export const dynamic = "force-dynamic"; /** Bugsink custom-webhook alerts (PEP-58). Unknown secret → 404; the policy runs after the reply. */ export async function POST(req: Request, { params }: { params: Promise<{ secret: string }> }) { const { secret } = await params; const body = await req.json().catch(() => null); const r = await receiveBugsinkWebhook(db, secret, body, bugsinkFromEnv()); if (r.status === 200) after(() => processIncidents(db, { log: (m) => console.error(`[incidents] ${m}`) }).then(() => undefined)); return Response.json(r.body, { status: r.status }); }