Skip to content

Commit b32d9b8

Browse files
authored
fix: router type (#83)
1 parent 641cd16 commit b32d9b8

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

plugin/controller/lib/impl/http/HTTPControllerRegister.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import assert from 'assert';
2-
import KoaRouter from 'koa-router';
3-
import { Application, Context } from 'egg';
2+
import { Application, Router } from 'egg';
43
import {
54
CONTROLLER_META_DATA,
65
ControllerMetadata,
@@ -17,8 +16,8 @@ import { RootProtoManager } from '../../RootProtoManager';
1716
export class HTTPControllerRegister implements ControllerRegister {
1817
static instance?: HTTPControllerRegister;
1918

20-
private readonly router: KoaRouter<any, Context>;
21-
private readonly checkRouters: Map<string, KoaRouter<any, Context>>;
19+
private readonly router: Router;
20+
private readonly checkRouters: Map<string, Router>;
2221
private readonly eggContainerFactory: typeof EggContainerFactory;
2322
private controllerProtos: EggPrototype[] = [];
2423

@@ -31,7 +30,7 @@ export class HTTPControllerRegister implements ControllerRegister {
3130
return HTTPControllerRegister.instance;
3231
}
3332

34-
constructor(router: KoaRouter<any, Context>, eggContainerFactory: typeof EggContainerFactory) {
33+
constructor(router: Router, eggContainerFactory: typeof EggContainerFactory) {
3534
this.router = router;
3635
this.checkRouters = new Map();
3736
this.checkRouters.set('default', router);

plugin/controller/lib/impl/http/HTTPMethodRegister.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import assert from 'assert';
2-
import KoaRouter from 'koa-router';
3-
import { Context } from 'egg';
2+
import { Context, Router } from 'egg';
43
import {
54
EggContext,
65
HTTPControllerMeta,
@@ -25,8 +24,8 @@ const noop = () => {
2524
};
2625

2726
export class HTTPMethodRegister {
28-
private readonly router: KoaRouter<any, Context>;
29-
private readonly checkRouters: Map<string, KoaRouter<any, Context>>;
27+
private readonly router: Router;
28+
private readonly checkRouters: Map<string, Router>;
3029
private readonly controllerMeta: HTTPControllerMeta;
3130
private readonly methodMeta: HTTPMethodMeta;
3231
private readonly proto: EggPrototype;
@@ -36,8 +35,8 @@ export class HTTPMethodRegister {
3635
proto: EggPrototype,
3736
controllerMeta: HTTPControllerMeta,
3837
methodMeta: HTTPMethodMeta,
39-
router: KoaRouter<any, Context>,
40-
checkRouters: Map<string, KoaRouter<any, Context>>,
38+
router: Router,
39+
checkRouters: Map<string, Router>,
4140
eggContainerFactory: typeof EggContainerFactory,
4241
) {
4342
this.proto = proto;
@@ -133,14 +132,14 @@ export class HTTPMethodRegister {
133132
});
134133
}
135134

136-
private registerToRouter(router: KoaRouter<any, Context>) {
135+
private registerToRouter(router: Router) {
137136
const routerFunc = router[this.methodMeta.method.toLowerCase()];
138137
const methodRealPath = this.controllerMeta.getMethodRealPath(this.methodMeta);
139138
const methodName = this.controllerMeta.getMethodName(this.methodMeta);
140139
Reflect.apply(routerFunc, router, [ methodName, methodRealPath, noop ]);
141140
}
142141

143-
private checkDuplicateInRouter(router: KoaRouter<any, Context>) {
142+
private checkDuplicateInRouter(router: Router) {
144143
const methodRealPath = this.controllerMeta.getMethodRealPath(this.methodMeta);
145144
const matched = router.match(methodRealPath, this.methodMeta.method);
146145
const methodName = this.controllerMeta.getMethodName(this.methodMeta);

plugin/controller/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"@eggjs/tegg-loader": "^3.2.4",
5454
"@eggjs/tegg-metadata": "^3.2.4",
5555
"@eggjs/tegg-runtime": "^3.2.4",
56-
"@types/koa-router": "^7.0.40",
5756
"egg-errors": "^2.3.0",
5857
"globby": "^10.0.2",
5958
"koa-compose": "^3.2.1",
@@ -71,7 +70,6 @@
7170
"egg-mock": "^5.5.0",
7271
"egg-tracer": "^2.0.0",
7372
"globby": "^11.1.0",
74-
"koa-router": "^8.0.8",
7573
"mocha": "^10.2.0",
7674
"ts-node": "^10.9.1",
7775
"typescript": "^4.9.4"

0 commit comments

Comments
 (0)