Every app/api route handler now goes through withRouteLogging, which logs a correlated reqId/method/path/status/duration for each request and turns any uncaught error into a logged stack trace plus a clean JSON 500 instead of Next's default opaque failure. proxy.ts logs rejected auth attempts, and instrumentation.ts's onRequestError catches anything that still escapes a route handler. Also adds a minimal not-found page matching the app's card styling. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
25 lines
936 B
TypeScript
25 lines
936 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { createRecording, listRecordings } from "@/lib/db/queries/recordings";
|
|
import { withRouteLogging } from "@/lib/api/with-route-logging";
|
|
|
|
const bodySchema = z.object({
|
|
sourcePlaySessionId: z.number().int().positive(),
|
|
name: z.string().min(1).max(160),
|
|
description: z.string().max(2000).optional(),
|
|
});
|
|
|
|
export const GET = withRouteLogging("recordings.list", async () => {
|
|
const rows = await listRecordings();
|
|
return NextResponse.json({ recordings: rows });
|
|
});
|
|
|
|
export const POST = withRouteLogging("recordings.create", async (req: Request) => {
|
|
const parsed = bodySchema.safeParse(await req.json().catch(() => null));
|
|
if (!parsed.success) {
|
|
return NextResponse.json({ error: parsed.error.message }, { status: 400 });
|
|
}
|
|
const recording = await createRecording(parsed.data);
|
|
return NextResponse.json({ recording }, { status: 201 });
|
|
});
|