Files

28 lines
857 B
JavaScript
Raw Permalink Normal View History

2026-03-18 10:54:18 +08:00
export default async function handler(req, res) {
2026-05-18 15:16:46 +08:00
const path = Array.isArray(req.query.path)
? req.query.path.join('/')
: req.query.path;
2026-03-18 10:54:18 +08:00
2026-05-18 15:16:46 +08:00
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}` : ''}`;
2026-03-18 10:54:18 +08:00
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);
}