feat: add API proxy routes for feedback and roadmap votes
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
const API_BASE_URL = process.env.API_BASE_URL || process.env.NEXT_PUBLIC_API_BASE_URL
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const body = await req.json()
|
||||
|
||||
const ip =
|
||||
req.headers.get('x-forwarded-for')?.split(',')[0]?.trim() ??
|
||||
req.headers.get('x-real-ip') ??
|
||||
'unknown'
|
||||
const userAgent = req.headers.get('user-agent') ?? 'unknown'
|
||||
|
||||
const res = await fetch(`${API_BASE_URL}/api/v1/feedback`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ...body, ipAddress: ip, userAgent }),
|
||||
cache: 'no-store',
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => '')
|
||||
console.error('[/api/feedback] Spring Boot error:', res.status, text)
|
||||
return NextResponse.json({ error: 'Failed to submit' }, { status: res.status })
|
||||
}
|
||||
|
||||
return NextResponse.json({ ok: true })
|
||||
} catch (e) {
|
||||
console.error('[/api/feedback] proxy error:', e)
|
||||
return NextResponse.json({ error: 'Invalid request' }, { status: 400 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user