Alexis Bruneteau 4c239c4552 feat: Add missing votes API proxy routes for blockchain queries
Created proxy routes to expose blockchain-related endpoints:
- GET /api/votes/public-keys - Get ElGamal public keys for vote encryption
- GET /api/votes/blockchain - Get blockchain state for an election
- GET /api/votes/results - Get election results from blockchain
- GET /api/votes/transaction-status - Check vote confirmation status

These routes forward requests to the backend and are required for the
frontend to access blockchain features like vote verification and
transaction status tracking.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-07 16:26:32 +01:00

46 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { getBackendUrl } from '@/lib/api-config'
export async function GET(request: NextRequest) {
try {
const backendUrl = getBackendUrl()
const searchParams = request.nextUrl.searchParams
const url = new URL('/api/votes', backendUrl)
searchParams.forEach((value, key) => url.searchParams.append(key, value))
const headers: HeadersInit = { 'Content-Type': 'application/json' }
const authHeader = request.headers.get('authorization')
if (authHeader) headers['Authorization'] = authHeader
const response = await fetch(url.toString(), { method: 'GET', headers })
const data = await response.json()
return NextResponse.json(data, { status: response.status })
} catch (error) {
const msg = error instanceof Error ? error.message : 'Unknown error'
return NextResponse.json({ detail: msg }, { status: 500 })
}
}
export async function POST(request: NextRequest) {
try {
const backendUrl = process.env.BACKEND_URL || 'http://nginx:8000'
const body = await request.json()
const headers: HeadersInit = { 'Content-Type': 'application/json' }
const authHeader = request.headers.get('authorization')
if (authHeader) headers['Authorization'] = authHeader
const response = await fetch(`${backendUrl}/api/votes`, {
method: 'POST',
headers,
body: JSON.stringify(body),
})
const data = await response.json()
return NextResponse.json(data, { status: response.status })
} catch (error) {
const msg = error instanceof Error ? error.message : 'Unknown error'
return NextResponse.json({ detail: msg }, { status: 500 })
}
}