2021-07-02 22:42:48 +08:00
|
|
|
import got from 'got';
|
2021-06-27 20:44:05 +08:00
|
|
|
import Koa from 'koa';
|
|
|
|
import Router from 'koa-router';
|
2021-07-02 22:42:48 +08:00
|
|
|
import { promisify } from 'util';
|
|
|
|
import stream from 'stream';
|
2021-07-02 22:55:14 +08:00
|
|
|
import { signInRoute } from '@/consts';
|
|
|
|
import { getEnv } from '@/utils';
|
2021-06-27 20:44:05 +08:00
|
|
|
|
2021-07-02 22:42:48 +08:00
|
|
|
const pipeline = promisify(stream.pipeline);
|
2021-06-27 20:44:05 +08:00
|
|
|
const router = new Router();
|
|
|
|
|
2021-07-02 22:42:48 +08:00
|
|
|
router.get(new RegExp(`^${signInRoute}(?:/|$)`), async (ctx) => {
|
|
|
|
// CAUTION: this is for dev purpose only, add a switch if needed
|
|
|
|
await pipeline(got.stream.get(getEnv('PLAYGROUND_URL')), ctx.res);
|
2021-06-27 20:44:05 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export default function initRouter(app: Koa): void {
|
|
|
|
app.use(router.routes()).use(router.allowedMethods());
|
|
|
|
}
|