Test/prevent server block on rate limit (#432)

This commit is contained in:
ZaydSkaff
2025-06-24 14:56:02 +03:00
committed by GitHub
parent 147cf0b582
commit e58d2d4831
2 changed files with 7 additions and 13 deletions

View File

@ -37,6 +37,7 @@ import { VisitorPasswordModule } from './vistor-password/visitor-password.module
import { ThrottlerGuard } from '@nestjs/throttler';
import { ThrottlerModule } from '@nestjs/throttler/dist/throttler.module';
import { isArray } from 'class-validator';
import { winstonLoggerOptions } from '../libs/common/src/logger/services/winston.logger';
import { AqiModule } from './aqi/aqi.module';
import { OccupancyModule } from './occupancy/occupancy.module';
@ -50,7 +51,12 @@ import { WeatherModule } from './weather/weather.module';
throttlers: [{ ttl: 60000, limit: 30 }],
generateKey: (context) => {
const req = context.switchToHttp().getRequest();
return req.headers['x-forwarded-for'] || req.ip;
console.log('Real IP:', req.headers['x-forwarded-for']);
return req.headers['x-forwarded-for']
? isArray(req.headers['x-forwarded-for'])
? req.headers['x-forwarded-for'][0].split(':')[0]
: req.headers['x-forwarded-for'].split(':')[0]
: req.ip;
},
}),
WinstonModule.forRoot(winstonLoggerOptions),