企业微信智能机器人API插件
This commit is contained in:
@@ -6,10 +6,19 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { Observable, map } from 'rxjs';
|
||||
|
||||
function skipResponseWrap(url?: string): boolean {
|
||||
const path = (url || '').split('?')[0];
|
||||
return path.endsWith('/wecom/plugin/openapi.json');
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ResponseInterceptor implements NestInterceptor {
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
|
||||
const req = context.switchToHttp().getRequest<{ originalUrl?: string; url?: string }>();
|
||||
const res = context.switchToHttp().getResponse<{ headersSent?: boolean }>();
|
||||
if (skipResponseWrap(req.originalUrl || req.url)) {
|
||||
return next.handle();
|
||||
}
|
||||
return next.handle().pipe(
|
||||
map((data) => {
|
||||
if (res.headersSent) return data;
|
||||
@@ -22,3 +31,4 @@ export class ResponseInterceptor implements NestInterceptor {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user