22 lines
540 B
TypeScript
22 lines
540 B
TypeScript
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()
|
|
.pipe(
|
|
tap(() => console.log(`after... ${Date.now() - now}ms`))
|
|
);
|
|
}
|
|
}
|