import { NextResponse } from 'next/server' import { generateCaptcha, verifyCaptcha } from '@/lib/captcha' export const runtime = 'nodejs' export async function GET() { try { const captchaData = generateCaptcha() return NextResponse.json({ success: true, captchaId: captchaData.captchaId, question: captchaData.question }) } catch (error) { console.error('Captcha generation error:', error) return NextResponse.json({ success: false, error: 'Failed to generate captcha' }, { status: 500 }) } } export async function POST(request: Request) { try { const { captchaId, answer } = await request.json() if (!captchaId || answer === undefined) { return NextResponse.json({ success: false, error: 'Missing captcha ID or answer' }, { status: 400 }) } const isValid = verifyCaptcha(captchaId, answer) return NextResponse.json({ success: true, valid: isValid }) } catch (error) { console.error('Captcha verification error:', error) return NextResponse.json({ success: false, error: 'Failed to verify captcha' }, { status: 500 }) } }