0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00
logto/packages/core/src/init/router.ts

20 lines
611 B
TypeScript
Raw Normal View History

import got from 'got';
2021-06-27 20:44:05 +08:00
import Koa from 'koa';
import Router from 'koa-router';
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
const pipeline = promisify(stream.pipeline);
2021-06-27 20:44:05 +08:00
const router = new Router();
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());
}