Skip to content

Commit da97145

Browse files
authored
Merge pull request #238 from lidofinance/develop
Develop to main
2 parents a0c6e53 + ba53fe8 commit da97145

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/http/common/middleware/logger.middleware.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { Inject, Injectable, LoggerService, NestMiddleware } from '@nestjs/common';
2-
import { LOGGER_PROVIDER } from '@lido-nestjs/logger';
2+
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
33
import { Request, Reply } from './interfaces';
4+
import { FastifyRequest } from 'fastify';
45

56
@Injectable()
67
export class LoggerMiddleware implements NestMiddleware {
7-
constructor(@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService) {}
8+
constructor(
9+
@Inject(WINSTON_MODULE_NEST_PROVIDER)
10+
private readonly logger: LoggerService,
11+
) {}
812

9-
use(request: Request, reply: Reply, next: () => void) {
13+
use(request: any, reply: Reply, next: () => void) {
1014
const { ip, method, headers, originalUrl } = request;
1115
const userAgent = headers['user-agent'] ?? '';
1216

17+
const ips = request.ips ? request.ips : [];
18+
1319
reply.on('finish', () => {
1420
const { statusCode } = reply;
15-
const log = { method, originalUrl, statusCode, userAgent, ip };
21+
const log = { method, originalUrl, statusCode, userAgent, ip, ips };
1622

17-
this.logger.log('Query', log);
23+
this.logger.log(JSON.stringify(log));
1824
});
1925

2026
next();

src/http/common/throttler/throttler.guard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import { FastifyRequest } from 'fastify';
55
@Injectable()
66
export class ThrottlerBehindProxyGuard extends ThrottlerGuard {
77
protected async getTracker(request: FastifyRequest) {
8-
return request.ips?.length ? request.ips[0] : request.ip;
8+
return request.ip;
99
}
1010
}

0 commit comments

Comments
 (0)