diff options
Diffstat (limited to 'apps/web/src/app/api')
| -rw-r--r-- | apps/web/src/app/api/feedback/route.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/apps/web/src/app/api/feedback/route.ts b/apps/web/src/app/api/feedback/route.ts new file mode 100644 index 00000000..b13ec2bf --- /dev/null +++ b/apps/web/src/app/api/feedback/route.ts @@ -0,0 +1,31 @@ +import { type NextRequest, NextResponse } from "next/server"; +import { z } from "zod"; +import { checkRateLimit } from "@/lib/rate-limit"; +import { submitFeedback, MAX_MESSAGE_LENGTH } from "@/lib/feedback"; + +const submitSchema = z.object({ + message: z + .string() + .min(1, "Message is required") + .max(MAX_MESSAGE_LENGTH, "Message too long"), +}); + +export async function POST(request: NextRequest) { + const { limited } = await checkRateLimit({ request }); + if (limited) { + return NextResponse.json({ error: "Too many requests" }, { status: 429 }); + } + + const body = await request.json(); + const result = submitSchema.safeParse(body); + + if (!result.success) { + return NextResponse.json( + { error: "Invalid input", details: result.error.flatten().fieldErrors }, + { status: 400 }, + ); + } + + const entry = await submitFeedback(result.data); + return NextResponse.json({ entry }, { status: 201 }); +} |
