import { Configuration, App, ILifeCycle } from "@midwayjs/core"; import * as Koa from "@midwayjs/koa"; import * as Sequelize from "@midwayjs/sequelize"; import * as CacheManager from "@midwayjs/cache-manager"; import { join } from "path"; import { AuthMiddleware } from "./middleware/auth.middleware"; import { RbacMiddleware } from "./middleware/rbac.middleware"; import { LogMiddleware } from "./middleware/log.middleware"; @Configuration({ imports: [Koa, Sequelize, CacheManager], importConfigs: [join(__dirname, "./config")] }) export class ContainerConfigLifeCycle implements ILifeCycle { @App() app!: Koa.Application; async onReady() { // 注册全局中间件(顺序:鉴权 → 权限 → 日志) this.app.useMiddleware([AuthMiddleware, RbacMiddleware, LogMiddleware]); console.log("智能物联网设备后台管理系统启动成功"); } async onStop() { console.log("系统已停止"); } }