23 lines
1.0 KiB
TypeScript

export async function GET(req: Request) {
try {
const url = new URL(req.url);
const parts = url.pathname.split('/');
const id = parts[parts.length - 1] || '';
if (!id) return new Response(JSON.stringify({ error: 'missing id' }), { status: 400, headers: { 'content-type': 'application/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 resp = await fetch(`${backend.replace(/\/$/, '')}/api/session/${encodeURIComponent(id)}`);
const text = await resp.text();
const headers = { 'content-type': 'application/json' };
return new Response(text, { status: resp.status, headers });
} catch (err) {
console.error('proxy GET /api/session/:id error', err);
return new Response(JSON.stringify({ error: 'internal' }), { status: 500, headers: { 'content-type': 'application/json' } });
}
}