mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-11-16 21:07:02 +03:00
feat!(): add custom execution context
This commit is contained in:
20
sample/common/interceptors/response-time.interceptor.ts
Normal file
20
sample/common/interceptors/response-time.interceptor.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common';
|
||||
import { Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class ResponseTimeInterceptor implements NestInterceptor {
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
||||
console.log('Before...');
|
||||
|
||||
const start = Date.now();
|
||||
return next
|
||||
.handle()
|
||||
.pipe(tap(() => console.log(`Response time: ${Date.now() - start}ms`)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user