fix: 修改路由解析问题
This commit is contained in:
parent
4d88a33856
commit
b6e9c05d1f
@ -1,20 +1,20 @@
|
|||||||
import * as Router from 'koa-router';
|
import * as Router from 'koa-router';
|
||||||
import { Context } from 'koa';
|
import { Context } from 'koa';
|
||||||
import { RouterOptions, surveyAppKey, surveyServerKey } from './decorator';
|
import { RouterOptions, surveyAppKey, surveyServerKey } from './decorator';
|
||||||
import { glob } from 'glob';
|
import Security from './apps/security';
|
||||||
import * as path from 'path';
|
import SurveyManage from './apps/surveyManage';
|
||||||
|
import SurveyPublish from './apps/surveyPublish';
|
||||||
|
import UI from './apps/ui';
|
||||||
|
import User from './apps/user';
|
||||||
import appRegistry from './registry';
|
import appRegistry from './registry';
|
||||||
|
|
||||||
|
|
||||||
export async function initRouter(app) {
|
export async function initRouter(app) {
|
||||||
const rootRouter = new Router();
|
const rootRouter = new Router();
|
||||||
const jsEntries = await glob(path.join(__dirname, './apps/*/index.js'));
|
const apps = [Security, SurveyManage, SurveyPublish, UI, User];
|
||||||
const tsEntries = await glob(path.join(__dirname, './apps/*/index.ts'));
|
|
||||||
const entries = Array.isArray(jsEntries) && jsEntries.length > 0 ? jsEntries : tsEntries;
|
|
||||||
|
|
||||||
for (const entry of entries) {
|
for (const subApp of apps) {
|
||||||
const module = await import(entry);
|
const instance = new subApp();
|
||||||
const instance = new module.default();
|
|
||||||
|
|
||||||
const moduleRouter = new Router();
|
const moduleRouter = new Router();
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ export async function initRouter(app) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rootRouter.use(module.default[surveyAppKey], moduleRouter.routes());
|
rootRouter.use(subApp[surveyAppKey], moduleRouter.routes());
|
||||||
|
|
||||||
appRegistry.registerApp(instance.constructor.name.toLowerCase(), instance);
|
appRegistry.registerApp(instance.constructor.name.toLowerCase(), instance);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user