mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 19:34:54 +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 { UserModule } from './users/user.module';
|
||||||
import { VisitorPasswordModule } from './vistor-password/visitor-password.module';
|
import { VisitorPasswordModule } from './vistor-password/visitor-password.module';
|
||||||
|
|
||||||
|
import { ThrottlerGuard } from '@nestjs/throttler';
|
||||||
import { ThrottlerModule } from '@nestjs/throttler/dist/throttler.module';
|
import { ThrottlerModule } from '@nestjs/throttler/dist/throttler.module';
|
||||||
import { winstonLoggerOptions } from '../libs/common/src/logger/services/winston.logger';
|
import { winstonLoggerOptions } from '../libs/common/src/logger/services/winston.logger';
|
||||||
import { AqiModule } from './aqi/aqi.module';
|
import { AqiModule } from './aqi/aqi.module';
|
||||||
import { OccupancyModule } from './occupancy/occupancy.module';
|
import { OccupancyModule } from './occupancy/occupancy.module';
|
||||||
import { WeatherModule } from './weather/weather.module';
|
import { WeatherModule } from './weather/weather.module';
|
||||||
import { ThrottlerGuard } from '@nestjs/throttler';
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot({
|
ConfigModule.forRoot({
|
||||||
@ -48,6 +48,10 @@ import { ThrottlerGuard } from '@nestjs/throttler';
|
|||||||
}),
|
}),
|
||||||
ThrottlerModule.forRoot({
|
ThrottlerModule.forRoot({
|
||||||
throttlers: [{ ttl: 60000, limit: 30 }],
|
throttlers: [{ ttl: 60000, limit: 30 }],
|
||||||
|
generateKey: (context) => {
|
||||||
|
const req = context.switchToHttp().getRequest();
|
||||||
|
return req.headers['x-forwarded-for'] || req.ip;
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
WinstonModule.forRoot(winstonLoggerOptions),
|
WinstonModule.forRoot(winstonLoggerOptions),
|
||||||
ClientModule,
|
ClientModule,
|
||||||
|
|||||||
@ -22,7 +22,12 @@ async function bootstrap() {
|
|||||||
app.use(new RequestContextMiddleware().use);
|
app.use(new RequestContextMiddleware().use);
|
||||||
|
|
||||||
app.use((req, res, next) => {
|
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();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user