mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-08-25 21:09:39 +00:00
test: use forwarded for heder to catch real IP
This commit is contained in:
@ -35,12 +35,12 @@ import { UserNotificationModule } from './user-notification/user-notification.mo
|
||||
import { UserModule } from './users/user.module';
|
||||
import { VisitorPasswordModule } from './vistor-password/visitor-password.module';
|
||||
|
||||
import { ThrottlerGuard } from '@nestjs/throttler';
|
||||
import { ThrottlerModule } from '@nestjs/throttler/dist/throttler.module';
|
||||
import { winstonLoggerOptions } from '../libs/common/src/logger/services/winston.logger';
|
||||
import { AqiModule } from './aqi/aqi.module';
|
||||
import { OccupancyModule } from './occupancy/occupancy.module';
|
||||
import { WeatherModule } from './weather/weather.module';
|
||||
import { ThrottlerGuard } from '@nestjs/throttler';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
@ -48,6 +48,10 @@ import { ThrottlerGuard } from '@nestjs/throttler';
|
||||
}),
|
||||
ThrottlerModule.forRoot({
|
||||
throttlers: [{ ttl: 60000, limit: 30 }],
|
||||
generateKey: (context) => {
|
||||
const req = context.switchToHttp().getRequest();
|
||||
return req.headers['x-forwarded-for'] || req.ip;
|
||||
},
|
||||
}),
|
||||
WinstonModule.forRoot(winstonLoggerOptions),
|
||||
ClientModule,
|
||||
|
@ -22,7 +22,12 @@ async function bootstrap() {
|
||||
app.use(new RequestContextMiddleware().use);
|
||||
|
||||
app.use((req, res, next) => {
|
||||
console.log('Real IP:', req.ip);
|
||||
console.log(
|
||||
'Real IP:',
|
||||
req.ip,
|
||||
req.headers['x-forwarded-for'],
|
||||
req.connection.remoteAddress,
|
||||
);
|
||||
next();
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user