Refine auth, API proxy, and server routing
This commit is contained in:
@@ -1,7 +1,17 @@
|
||||
export default async function handler(req, res) {
|
||||
const { 0: path } = req.query;
|
||||
const path = Array.isArray(req.query.path)
|
||||
? req.query.path.join('/')
|
||||
: req.query.path;
|
||||
|
||||
const backendUrl = `http://localhost:3501/${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,
|
||||
|
||||
Reference in New Issue
Block a user