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>
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { listPlaySessions, startPlaySession } from "@/lib/db/queries/play-sessions";
|
|
import { withRouteLogging } from "@/lib/api/with-route-logging";
|
|
|
|
const deviceInputSchema = z.object({
|
|
slotLabel: z.string().min(1),
|
|
bleName: z.string().min(1),
|
|
deviceClass: z.string().nullish(),
|
|
capabilities: z.object({ outputs: z.array(z.string()), featureCount: z.number() }).optional(),
|
|
});
|
|
|
|
const bodySchema = z.object({
|
|
kind: z.enum(["live", "replay"]),
|
|
replayedRecordingId: z.number().int().positive().optional(),
|
|
name: z.string().min(1).optional(),
|
|
devices: z.array(deviceInputSchema).min(1),
|
|
});
|
|
|
|
export const GET = withRouteLogging("play-sessions.list", async () => {
|
|
const rows = await listPlaySessions();
|
|
return NextResponse.json({ playSessions: rows });
|
|
});
|
|
|
|
export const POST = withRouteLogging("play-sessions.start", 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 result = await startPlaySession(parsed.data);
|
|
return NextResponse.json(result, { status: 201 });
|
|
});
|