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';
|
2021-08-11 09:13:08 -05:00
|
|
|
import sessionRoutes from '@/routes/session';
|
|
|
|
import userRoutes from '@/routes/user';
|
2021-07-23 10:10:54 -05:00
|
|
|
import swaggerRoutes from '@/routes/swagger';
|
2021-07-29 13:21:47 -05:00
|
|
|
import mount from 'koa-mount';
|
2021-06-27 07:44:05 -05:00
|
|
|
|
2021-07-03 08:19:20 -05:00
|
|
|
const createRouter = (provider: Provider): Router => {
|
2021-07-29 13:21:47 -05:00
|
|
|
const router = new Router();
|
2021-06-27 07:44:05 -05:00
|
|
|
|
2021-08-11 09:13:08 -05:00
|
|
|
sessionRoutes(router, provider);
|
|
|
|
userRoutes(router);
|
2021-07-29 13:21:47 -05:00
|
|
|
swaggerRoutes(router);
|
2021-06-27 07:44:05 -05:00
|
|
|
|
2021-07-03 08:19:20 -05:00
|
|
|
return router;
|
|
|
|
};
|
|
|
|
|
2021-07-29 13:21:47 -05:00
|
|
|
export default function initRouter(app: Koa, provider: Provider) {
|
2021-07-03 08:19:20 -05:00
|
|
|
const router = createRouter(provider);
|
2021-07-29 13:21:47 -05:00
|
|
|
const apisApp = new Koa().use(router.routes()).use(router.allowedMethods());
|
|
|
|
|
|
|
|
app.use(mount('/api', apisApp));
|
2021-06-27 07:44:05 -05:00
|
|
|
}
|