import { App, Configuration } from '@midwayjs/decorator'; import * as DefaultConfig from './config/config.default'; import * as koa from '@midwayjs/koa'; // 数据库 import * as typegoose from '@midwayjs/typegoose'; import * as Typegoose from '@typegoose/typegoose'; import { ResponseMiddleware } from './middleware/response.middleware'; import { DefaultErrorFilter } from './filter/default.filter'; @Configuration({ namespace: 'free', imports: [koa, typegoose], importConfigs: [ { default: DefaultConfig, }, ], }) export class FreeConfiguration { @App() app: koa.Application; getApiUrl() { const path = this.app.getConfig()?.swagger?.swaggerPath; const port = this.app.getConfig()?.koa?.port; if (path) console.log(`api文档: http://127.0.0.1:${port}${path}/index.html`); } async onReady() { // TODO something this.app.getMiddleware().insertLast(ResponseMiddleware); this.app.useFilter([DefaultErrorFilter]); Typegoose.setGlobalOptions({ schemaOptions: { id: true, toJSON: { getters: true, virtuals: true }, toObject: { getters: true, virtuals: true }, }, options: { allowMixed: Typegoose.Severity.ALLOW }, }); this.getApiUrl(); console.log('free frame is ready'); } }