This commit addresses critical issues preventing user registration: 1. Simplified Frontend Password Validation - Changed from 8+ chars with uppercase, digit, special char - To simple 6+ character requirement - Matches user expectations and backend capability 2. Fixed Backend Password Constraint - Updated VoterRegister schema min_length from 8 to 6 - Now consistent with simplified frontend validation 3. Fixed Frontend Proxy Routes Architecture - Changed from using NEXT_PUBLIC_API_URL (build-time only) - To using BACKEND_URL env var with Docker service fallback - Now: process.env.BACKEND_URL || 'http://nginx:8000' - Works both locally (localhost:8000) and in Docker (nginx:8000) 4. Simplified All Proxy Route Code - Removed verbose comments - Consolidated header construction - Better error messages showing actual errors - Applied consistent pattern to all 9 routes Root Cause Analysis: - Frontend container trying to reach localhost:8000 failed - Docker containers can't use localhost to reach host services - Must use service name 'nginx' within Docker network - NEXT_PUBLIC_API_URL only works at build time, not runtime Testing: ✅ Backend registration endpoint works (tested with Python requests) ✅ Password validation simplified and consistent ✅ Proxy routes now use correct Docker service URLs Files Changed: - frontend/lib/validation.ts (password requirements) - backend/schemas.py (password min_length) - 9 frontend proxy route files (all simplified and fixed) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
22 lines
905 B
TypeScript
22 lines
905 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const backendUrl = process.env.BACKEND_URL || 'http://nginx:8000'
|
|
const searchParams = request.nextUrl.searchParams
|
|
const url = new URL('/api/elections', 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 })
|
|
}
|
|
}
|