Feat: add forward addr

This commit is contained in:
unitwk 2022-11-05 22:36:55 +08:00
parent 239d0cd0b7
commit 75ee272d3a

View File

@ -207,4 +207,26 @@ router.get("/quick_install_list", permission({ level: 10 }), async (ctx) => {
}
});
// [Top-level Permission]
// forward request
router.all(
"/forward",
permission({ level: 10 }),
validator({ query: { target: String } }),
async (ctx) => {
const ADDR = String(ctx.query.target);
try {
const response = await axios.request({
method: ctx.request.method,
url: ADDR,
data: ctx.request.body
});
if (response.status !== 200) throw new Error("Response code != 200");
ctx.body = response.data;
} catch (err) {
ctx.body = [];
}
}
);
export default router;