base con autenticacion, registro, modulo encuestas
This commit is contained in:
1
apps/api/src/common/interceptors/index.ts
Normal file
1
apps/api/src/common/interceptors/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './req-log.interceptor';
|
||||
36
apps/api/src/common/interceptors/req-log.interceptor.ts
Normal file
36
apps/api/src/common/interceptors/req-log.interceptor.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { concatStr } from '@/common/utils';
|
||||
import {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
Logger,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common';
|
||||
import { Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class ReqLogInterceptor implements NestInterceptor {
|
||||
private readonly logger: Logger;
|
||||
constructor() {
|
||||
this.logger = new Logger('REQUEST INTERCEPTOR', { timestamp: true });
|
||||
}
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
||||
const req = context.switchToHttp().getRequest();
|
||||
const res = context.switchToHttp().getResponse();
|
||||
/* *
|
||||
* Before the request is handled, log the request details
|
||||
* */
|
||||
this.logger.log(concatStr([req.method, req.originalUrl]));
|
||||
return next.handle().pipe(
|
||||
tap(() =>
|
||||
/* *
|
||||
* After the request is handled, log the response details
|
||||
* */
|
||||
this.logger.log(
|
||||
concatStr([req.method, req.originalUrl, res.statusCode]),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user