添加了一个pipe打印处理完handler的耗时

This commit is contained in:
Jeremy Yin 2019-06-19 23:06:35 +08:00
parent efb6fe6a14
commit 3a04b50060
1 changed files with 11 additions and 1 deletions

View File

@ -1,11 +1,21 @@
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators'
@Injectable()
export class LoggingInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
console.log('I am a interceptor!')
const now = Date.now();
console.log('before...');
return next.handle();
return next
.handle()
.pipe(
tap(() => console.log(`after... ${Date.now() - now}ms`))
);
}
}