blob: b13ec2bf754cf9c34cbe3a199eaba3f147b87f0a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 });
}
|