添加了一个pipe打印处理完handler的耗时
This commit is contained in:
parent
efb6fe6a14
commit
3a04b50060
|
@ -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`))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue