File size: 606 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import type { NextApiRequest, NextApiResponse } from "next";
export default async function Handler(
req: NextApiRequest,
res: NextApiResponse,
) {
const form = new URLSearchParams();
form.append("secret", process.env.CLOUDFLARE_TURNSTILE_SECRET_KEY);
form.append("response", req.body["cf-turnstile-response"]);
form.append("remoteip", req.headers["x-forwarded-for"] as string);
const result = await fetch(
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
{ method: "POST", body: form },
);
const json = await result.json();
res.status(result.status).json(json);
}
|