2021-06-27 07:44:05 -05:00
|
|
|
import Koa from 'koa';
|
|
|
|
import Router from 'koa-router';
|
2021-07-03 08:19:20 -05:00
|
|
|
import { Provider } from 'oidc-provider';
|
|
|
|
import createSignInRoutes from '@/routes/sign-in';
|
2021-07-04 02:01:02 -05:00
|
|
|
import createUIProxy from '@/proxies/ui';
|
2021-07-04 04:41:46 -05:00
|
|
|
import createRegisterRoutes from '@/routes/register';
|
2021-06-27 07:44:05 -05:00
|
|
|
|
2021-07-03 08:19:20 -05:00
|
|
|
const createRouter = (provider: Provider): Router => {
|
2021-07-04 04:41:46 -05:00
|
|
|
const router = new Router({ prefix: '/api' });
|
2021-06-27 07:44:05 -05:00
|
|
|
|
2021-07-04 04:41:46 -05:00
|
|
|
router.use(createSignInRoutes(provider));
|
|
|
|
router.use(createRegisterRoutes());
|
2021-06-27 07:44:05 -05:00
|
|
|
|
2021-07-03 08:19:20 -05:00
|
|
|
return router;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function initRouter(app: Koa, provider: Provider): Router {
|
|
|
|
const router = createRouter(provider);
|
2021-07-04 02:01:02 -05:00
|
|
|
app.use(router.routes()).use(createUIProxy()).use(router.allowedMethods());
|
2021-07-03 08:19:20 -05:00
|
|
|
return router;
|
2021-06-27 07:44:05 -05:00
|
|
|
}
|