39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
/**
|
|
* Proxy: POST /api/proxy/onramp/session
|
|
*
|
|
* Forwards session creation to the onramp-service so the frontend
|
|
* can initiate a Transak payment session without CORS issues.
|
|
*/
|
|
|
|
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
const ONRAMP_URL = process.env.ONRAMP_SERVICE_URL || 'http://payment-onramp:3002'
|
|
|
|
export async function POST(req: NextRequest) {
|
|
try {
|
|
const body = await req.json()
|
|
|
|
const res = await fetch(`${ONRAMP_URL}/api/onramp/transak/session`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
walletAddress: body.walletAddress,
|
|
fiatAmount: body.fiatAmount,
|
|
fiatCurrency: body.fiatCurrency,
|
|
email: body.email,
|
|
}),
|
|
})
|
|
|
|
if (!res.ok) {
|
|
const err = await res.text()
|
|
return NextResponse.json({ error: err }, { status: res.status })
|
|
}
|
|
|
|
const data = await res.json()
|
|
return NextResponse.json(data)
|
|
} catch (error) {
|
|
console.error('Onramp session proxy error:', error)
|
|
return NextResponse.json({ error: 'Failed to create session' }, { status: 500 })
|
|
}
|
|
}
|