Files
accountbook/frontend/pages/api/[...path].js
T

18 lines
547 B
JavaScript
Raw Normal View History

2026-03-18 10:54:18 +08:00
export default async function handler(req, res) {
const { 0: path } = req.query;
const backendUrl = `http://localhost:3501/${path}`;
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);
}