|
@@ -23,13 +23,15 @@ export class CheckTokenMiddleware
|
|
|
passTokenList: Array<string>;
|
|
|
@Config('tokenKey')
|
|
|
tokenKey: string;
|
|
|
+ @Config('koa.globalPrefix')
|
|
|
+ globalPrefix: string;
|
|
|
@Inject()
|
|
|
webRouterService: MidwayWebRouterService;
|
|
|
@Inject()
|
|
|
jwtService: JwtService;
|
|
|
|
|
|
+
|
|
|
async analysisToken(ctx: Context) {
|
|
|
-
|
|
|
const token: any = get(ctx.request, `header.${this.tokenKey}`);
|
|
|
if (token) {
|
|
|
const data = this.jwtService.decodeSync(token);
|
|
@@ -40,7 +42,16 @@ export class CheckTokenMiddleware
|
|
|
}
|
|
|
return token;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ async excludePrefixPath(ctx: Context) {
|
|
|
+
|
|
|
+ const routeInfo = await this.webRouterService.getMatchedRouterInfo(
|
|
|
+ ctx.path,
|
|
|
+ ctx.method
|
|
|
+ );
|
|
|
+ const fullUrl = routeInfo.fullUrl;
|
|
|
+ return fullUrl.replace(this.globalPrefix, '');
|
|
|
+ }
|
|
|
resolve() {
|
|
|
return async (ctx: Context, next: NextFunction) => {
|
|
|
console.log('in Middleware');
|
|
@@ -50,12 +61,7 @@ export class CheckTokenMiddleware
|
|
|
} else {
|
|
|
|
|
|
token = await this.analysisToken(ctx);
|
|
|
-
|
|
|
- const routeInfo = await this.webRouterService.getMatchedRouterInfo(
|
|
|
- ctx.path,
|
|
|
- ctx.method
|
|
|
- );
|
|
|
- const path = routeInfo.url as string;
|
|
|
+ const path = await this.excludePrefixPath(ctx);
|
|
|
|
|
|
if (this.passTokenList.includes(path)) {
|
|
|
|