|
@@ -1,16 +1,23 @@
|
|
|
import { IMiddleware } from '@midwayjs/core';
|
|
|
-import { Middleware } from '@midwayjs/decorator';
|
|
|
-import { NextFunction, Context } from '@midwayjs/koa';
|
|
|
+import { Middleware, App } from '@midwayjs/decorator';
|
|
|
+import { NextFunction, Context, Application } from '@midwayjs/koa';
|
|
|
import { VOBase } from '../interface/VOBase';
|
|
|
@Middleware()
|
|
|
export class ResponseMiddleware implements IMiddleware<Context, NextFunction> {
|
|
|
+ @App()
|
|
|
+ app: Application;
|
|
|
resolve() {
|
|
|
return async (ctx: Context, next: NextFunction) => {
|
|
|
await next();
|
|
|
- const response = ctx.response;
|
|
|
- const body = response.body;
|
|
|
- const nb = new VOBase(body as object);
|
|
|
- return nb;
|
|
|
+ // 过滤掉 api文档的请求
|
|
|
+ const swaggerPath = this.app.getConfig()?.swagger?.swaggerPath;
|
|
|
+ const url = _.get(ctx, 'request.originalUrl');
|
|
|
+ if (!url.includes(swaggerPath)) {
|
|
|
+ const response = ctx.response;
|
|
|
+ const body = response.body;
|
|
|
+ const nb = new VOBase(body as object);
|
|
|
+ return nb;
|
|
|
+ }
|
|
|
};
|
|
|
}
|
|
|
|