export declare const gateRoutesTemplate = "import { NextResponse } from \"next/server\";\nimport { cookies } from \"next/headers\";\nimport { GATE_COOKIE_NAME, gateToken, timingSafeEqual } from \"@/lib/siteGate\";\nimport { rateLimit } from \"@/utils/rateLimit\";\nimport { readJsonBody, RequestTooLargeError } from \"@/utils/requestBody\";\n\nconst MAX_GATE_ENVELOPE_BYTES = 8 * 1024;\n\nexport async function POST(req: Request) {\n const password = process.env.SITE_PASSWORD;\n if (!password) {\n return NextResponse.json({ ok: true });\n }\n\n // Use per-client buckets only for platform-authenticated address headers.\n const { allowed, retryAfter } = rateLimit(req);\n if (!allowed) {\n return NextResponse.json(\n { ok: false, error: \"Too many attempts\" },\n { status: 429, headers: { \"Retry-After\": String(retryAfter) } },\n );\n }\n\n let submitted: unknown;\n try {\n const body = await readJsonBody(req, MAX_GATE_ENVELOPE_BYTES);\n submitted =\n typeof body === \"object\" && body !== null && !Array.isArray(body)\n ? (body as Record).password\n : undefined;\n } catch (error: unknown) {\n if (req.signal.aborted) throw error;\n if (error instanceof RequestTooLargeError) {\n return NextResponse.json(\n { ok: false, error: \"Request body too large\" },\n { status: 413 },\n );\n }\n return NextResponse.json(\n { ok: false, error: \"Bad Request\" },\n { status: 400 },\n );\n }\n\n const expected = await gateToken(password);\n const candidate = await gateToken(\n typeof submitted === \"string\" ? submitted : \"\",\n );\n\n if (!timingSafeEqual(candidate, expected)) {\n return NextResponse.json(\n { ok: false, error: \"Incorrect password\" },\n { status: 401 },\n );\n }\n\n const cookieStore = await cookies();\n cookieStore.set(GATE_COOKIE_NAME, expected, {\n httpOnly: true,\n secure: process.env.NODE_ENV === \"production\",\n sameSite: \"lax\",\n path: \"/\",\n maxAge: 60 * 60 * 24 * 30, // 30 days\n });\n\n return NextResponse.json({ ok: true });\n}\n";