Compare commits

..

18 Commits

Author SHA1 Message Date
4ff62611fb Merge branch 'dev' into test/prevent-server-block-on-rate-limit 2025-06-24 14:55:39 +03:00
7d9fe170b9 test: new format of IP 2025-06-24 14:53:04 +03:00
f337e6c681 Test/prevent server block on rate limit (#421) 2025-06-24 10:55:38 +03:00
5ad5e7e934 test: use forwarded for heder to catch real IP 2025-06-24 10:46:14 +03:00
f5bf857071 Merge pull request #429 from SyncrowIOT/add-queue-event-handler
Add queue event handler
2025-06-23 08:13:36 -06:00
37b582f521 Merge pull request #428 from SyncrowIOT/add-queue-event-handler
Implement message queue for TuyaWebSocketService and batch processing
2025-06-23 07:35:22 -06:00
238a52bfa9 Merge branch 'dev' into test/prevent-server-block-on-rate-limit 2025-06-22 14:07:09 +03:00
f2a8ed141c test throttle module 2025-06-22 10:23:37 +03:00
bf64470288 increase DB max connection to 50 2025-06-19 14:31:16 +03:00
c1e9c6cbb7 Merge branch 'dev' into test/prevent-server-block-on-rate-limit 2025-06-19 13:42:55 +03:00
f28184975f revert all changes 2025-06-19 13:37:26 +03:00
130a1ed06e fix: merge conflicts 2025-06-19 12:53:34 +03:00
01d66a67d9 Merge branch 'dev' into test/prevent-server-block-on-rate-limit 2025-06-19 10:13:38 +03:00
069db9a3ea task: increase rate limit timeout 2025-06-19 10:11:51 +03:00
ce1986a27f Merge branch 'dev' into test/prevent-server-block-on-rate-limit 2025-06-19 09:44:01 +03:00
6857b4ea03 task: test rate limits on sever 2025-06-19 09:42:11 +03:00
e6c3fc7044 add logging 2025-06-18 12:05:09 +03:00
588eacdfef task: add trust proxy header 2025-06-18 12:00:27 +03:00
2 changed files with 18 additions and 21 deletions

View File

@ -1,7 +1,7 @@
import { SeederModule } from '@app/common/seed/seeder.module';
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import { WinstonModule } from 'nest-winston';
import { AuthenticationModule } from './auth/auth.module';
import { AutomationModule } from './automation/automation.module';
@ -35,6 +35,9 @@ 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 { 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';
@ -44,9 +47,18 @@ import { WeatherModule } from './weather/weather.module';
ConfigModule.forRoot({
load: config,
}),
/* ThrottlerModule.forRoot({
throttlers: [{ ttl: 100000, limit: 30 }],
}), */
ThrottlerModule.forRoot({
throttlers: [{ ttl: 60000, limit: 30 }],
generateKey: (context) => {
const req = context.switchToHttp().getRequest();
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),
ClientModule,
AuthenticationModule,
@ -88,10 +100,10 @@ import { WeatherModule } from './weather/weather.module';
provide: APP_INTERCEPTOR,
useClass: LoggingInterceptor,
},
/* {
{
provide: APP_GUARD,
useClass: ThrottlerGuard,
}, */
},
],
})
export class AppModule {}

View File

@ -3,7 +3,6 @@ import { SeederService } from '@app/common/seed/services/seeder.service';
import { Logger, ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { json, urlencoded } from 'body-parser';
import rateLimit from 'express-rate-limit';
import helmet from 'helmet';
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
import { setupSwaggerAuthentication } from '../libs/common/src/util/user-auth.swagger.utils';
@ -22,20 +21,6 @@ async function bootstrap() {
app.use(new RequestContextMiddleware().use);
app.use(
rateLimit({
windowMs: 5 * 60 * 1000,
max: 500,
}),
);
app.use((req, res, next) => {
console.log('Real IP:', req.ip);
next();
});
// app.getHttpAdapter().getInstance().set('trust proxy', 1);
app.use(
helmet({
contentSecurityPolicy: false,