0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00
logto/packages/core/src/routes/init.ts

25 lines
678 B
TypeScript
Raw Normal View History

2021-06-27 07:44:05 -05:00
import Koa from 'koa';
import Router from 'koa-router';
import { Provider } from 'oidc-provider';
import sessionRoutes from '@/routes/session';
import userRoutes from '@/routes/user';
2021-07-23 10:10:54 -05:00
import swaggerRoutes from '@/routes/swagger';
import mount from 'koa-mount';
2021-06-27 07:44:05 -05:00
const createRouter = (provider: Provider): Router => {
const router = new Router();
2021-06-27 07:44:05 -05:00
sessionRoutes(router, provider);
userRoutes(router);
swaggerRoutes(router);
2021-06-27 07:44:05 -05:00
return router;
};
export default function initRouter(app: Koa, provider: Provider) {
const router = createRouter(provider);
const apisApp = new Koa().use(router.routes()).use(router.allowedMethods());
app.use(mount('/api', apisApp));
2021-06-27 07:44:05 -05:00
}