function Proxy(app, from, to) { this._router = KoaRouter({ prefix: from }); this._router.all('(.*)', async (ctx) => { if (!app._webProxy) { app._webProxy = await makeProxy(to); } ctx.redirect(`http://${ctx.request.header.host}:${app._webProxy.port}${ctx.params[0] || ''}`); ctx.status = TEMPORARY_REDIRECT; }); }
function Redirect(from, url) { this._router = KoaRouter({ prefix: from }); this._router.all('/', async (ctx) => { ctx.redirect(url); ctx.status = TEMPORARY_REDIRECT; }); }