import { IMiddleware, Inject, MidwayWebRouterService } from '@midwayjs/core'; import { Middleware } from '@midwayjs/decorator'; import { NextFunction, Context } from '@midwayjs/koa'; import { LoginService } from '../service/login.service'; @Middleware() export class CheckOnePointLoginMiddleware implements IMiddleware { @Inject() webRouterService: MidwayWebRouterService; resolve() { return async (ctx: Context, next: NextFunction) => { const routeInfo = await this.webRouterService.getMatchedRouterInfo(ctx.path, ctx.method); if(!routeInfo) { await next() return } const desc = routeInfo.description; if (desc === 'ignore') { const loginService = await ctx.requestContext.getAsync(LoginService); await loginService.onePointCheck(); } await next(); }; } static getName(): string { return 'checkOnePonitLogin'; } }