20 lines
914 B
TypeScript
20 lines
914 B
TypeScript
export async function POST(req: Request) {
|
|
try {
|
|
const body = await req.json();
|
|
const backend = process.env.BACKEND_URL || process.env.VITE_BACKEND_TOKENS_URL || '';
|
|
if (!backend) {
|
|
return new Response(JSON.stringify({ error: 'BACKEND_URL not configured' }), { status: 500, headers: { 'content-type': 'application/json' } });
|
|
}
|
|
|
|
const url = `${backend.replace(/\/$/, '')}/api/session`;
|
|
const resp = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
|
|
const text = await resp.text();
|
|
const headers = { 'content-type': 'application/json' };
|
|
return new Response(text, { status: resp.status, headers });
|
|
} catch (err) {
|
|
console.error('proxy /api/session error', err);
|
|
return new Response(JSON.stringify({ error: 'internal' }), { status: 500, headers: { 'content-type': 'application/json' } });
|
|
}
|
|
}
|
|
|