midway
midway copied to clipboard
动态添加的路由优先级不符合预期
- Node Version: v16.15.0
- Midway Version(Decorator/Core): 3.4.11 / 3.5.1
- Component Name/Version: -
- Platform: Mac OS
- Mini Showcase Repository: -
// controller/home.ts
@Controller('/')
export class HomeController {
@Get('/**')
async home() {
return 'main';
}
@Get('/test/**')
async test() {
return 'catch-all';
}
}
// configuration.ts
@Configuration({
imports: [egg],
importConfigs: [join(__dirname, './config')],
})
export class ContainerLifeCycle implements ILifeCycle {
@App()
app: Application;
async onReady() {
const router = this.app.applicationContext.get(MidwayWebRouterService);
// (a)
const info = await router.getFlattenRouterTable();
console.log(info);
router.addRouter(
ctx => {
ctx.body = 'test';
},
{
requestMethod: 'GET',
// (b.1) This works as expected.
url: '/asd',
prefix: '/test',
// (b.2) This is buggy
// url: '/test/asd',
}
);
// (c)
(router as any).sortPrefixAndRouter();
}
}
- 当使用
(b.2)的代码时,预期返回test,实际返回catch-all;使用(b.1)的代码时,返回test; - 在使用
(b.2)的代码时,当存在(a)调用,必须增加(c)调用,否则返回catch-all