2025-08-05 17:09:43 +02:00
|
|
|
import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
|
|
|
|
import { ConfigModule } from '@nestjs/config';
|
|
|
|
import { APP_GUARD } from '@nestjs/core';
|
|
|
|
|
|
|
|
import { DatabaseModule } from './database/database.module';
|
|
|
|
import { AuthModule } from './auth/auth.module';
|
|
|
|
import { UsersModule } from './users/users.module';
|
2025-08-05 17:24:53 +02:00
|
|
|
import { StorageModule } from './storage/storage.module';
|
|
|
|
import { UploadModule } from './upload/upload.module';
|
|
|
|
import { QueueModule } from './queue/queue.module';
|
|
|
|
import { WebSocketModule } from './websocket/websocket.module';
|
|
|
|
import { BatchesModule } from './batches/batches.module';
|
|
|
|
import { ImagesModule } from './images/images.module';
|
|
|
|
import { KeywordsModule } from './keywords/keywords.module';
|
2025-08-05 17:09:43 +02:00
|
|
|
import { JwtAuthGuard } from './auth/auth.guard';
|
|
|
|
import { RateLimitMiddleware } from './common/middleware/rate-limit.middleware';
|
|
|
|
import { SecurityMiddleware } from './common/middleware/security.middleware';
|
|
|
|
|
|
|
|
@Module({
|
|
|
|
imports: [
|
|
|
|
ConfigModule.forRoot({
|
|
|
|
isGlobal: true,
|
|
|
|
envFilePath: ['.env.local', '.env'],
|
|
|
|
cache: true,
|
|
|
|
}),
|
|
|
|
DatabaseModule,
|
|
|
|
AuthModule,
|
|
|
|
UsersModule,
|
2025-08-05 17:24:53 +02:00
|
|
|
StorageModule,
|
|
|
|
UploadModule,
|
|
|
|
QueueModule,
|
|
|
|
WebSocketModule,
|
|
|
|
BatchesModule,
|
|
|
|
ImagesModule,
|
|
|
|
KeywordsModule,
|
2025-08-05 17:09:43 +02:00
|
|
|
],
|
|
|
|
providers: [
|
|
|
|
{
|
|
|
|
provide: APP_GUARD,
|
|
|
|
useClass: JwtAuthGuard,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
export class AppModule implements NestModule {
|
|
|
|
configure(consumer: MiddlewareConsumer) {
|
|
|
|
// Apply security middleware to all routes
|
|
|
|
consumer
|
|
|
|
.apply(SecurityMiddleware)
|
|
|
|
.forRoutes('*');
|
|
|
|
|
|
|
|
// Apply rate limiting to authentication routes
|
|
|
|
consumer
|
|
|
|
.apply(RateLimitMiddleware)
|
|
|
|
.forRoutes('auth/*');
|
|
|
|
}
|
|
|
|
}
|