export default async function handler(req, res) { const path = Array.isArray(req.query.path) ? req.query.path.join('/') : req.query.path; if (!path) { res.status(400).json({ error: 'Missing API path' }); return; } const query = { ...req.query }; delete query.path; const searchParams = new URLSearchParams(query); const backendUrl = `http://localhost:3501/api/${path}${searchParams.size ? `?${searchParams}` : ''}`; const response = await fetch(backendUrl, { method: req.method, headers: { 'Content-Type': 'application/json', ...(req.headers.authorization ? { Authorization: req.headers.authorization } : {}), }, body: req.method !== 'GET' && req.method !== 'HEAD' ? JSON.stringify(req.body) : undefined, }); const data = await response.json(); res.status(response.status).json(data); }