- Add @nestjs/throttler for rate limiting support - Configure multiple throttle profiles: default (100/min), strict (10/min for spawn/kill), status (200/min for polling) - Apply strict rate limits to spawn and kill endpoints to prevent DoS - Apply higher rate limits to status/health endpoints for monitoring - Add OrchestratorThrottlerGuard with X-Forwarded-For support for proxy setups - Add unit tests for throttler guard Refs #338 Co-Authored-By: Claude Opus 4.5 <[email protected]>
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { Module } from "@nestjs/common";
|
|
import { ConfigModule } from "@nestjs/config";
|
|
import { BullModule } from "@nestjs/bullmq";
|
|
import { ThrottlerModule } from "@nestjs/throttler";
|
|
import { HealthModule } from "./api/health/health.module";
|
|
import { AgentsModule } from "./api/agents/agents.module";
|
|
import { CoordinatorModule } from "./coordinator/coordinator.module";
|
|
import { BudgetModule } from "./budget/budget.module";
|
|
import { orchestratorConfig } from "./config/orchestrator.config";
|
|
|
|
/**
|
|
* Rate limiting configuration:
|
|
* - 'default': Standard API endpoints (100 requests per minute)
|
|
* - 'strict': Spawn/kill endpoints (10 requests per minute) - prevents DoS
|
|
* - 'status': Status/health endpoints (200 requests per minute) - higher for polling
|
|
*/
|
|
@Module({
|
|
imports: [
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
load: [orchestratorConfig],
|
|
}),
|
|
BullModule.forRoot({
|
|
connection: {
|
|
host: process.env.VALKEY_HOST ?? "localhost",
|
|
port: parseInt(process.env.VALKEY_PORT ?? "6379"),
|
|
},
|
|
}),
|
|
ThrottlerModule.forRoot([
|
|
{
|
|
name: "default",
|
|
ttl: 60000, // 1 minute
|
|
limit: 100, // 100 requests per minute
|
|
},
|
|
{
|
|
name: "strict",
|
|
ttl: 60000, // 1 minute
|
|
limit: 10, // 10 requests per minute for spawn/kill
|
|
},
|
|
{
|
|
name: "status",
|
|
ttl: 60000, // 1 minute
|
|
limit: 200, // 200 requests per minute for status endpoints
|
|
},
|
|
]),
|
|
HealthModule,
|
|
AgentsModule,
|
|
CoordinatorModule,
|
|
BudgetModule,
|
|
],
|
|
})
|
|
export class AppModule {}
|