-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathapp.module.ts
More file actions
125 lines (117 loc) · 4.17 KB
/
app.module.ts
File metadata and controls
125 lines (117 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { Module } from '@nestjs/common';
import { APP_GUARD } from '@nestjs/core';
import { ConfigModule } from '@nestjs/config';
import { join } from 'node:path';
import { ThrottlerModule, ThrottlerGuard, seconds } from '@nestjs/throttler';
import { ThrottlerStorageRedisService } from '@nest-lab/throttler-storage-redis';
import Redis from 'ioredis';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { authConfig } from './config/auth.config';
import { opensearchConfig } from './config/opensearch.config';
import { validateBackendEnv } from './config/env.validate';
import { OpenSearchModule } from './config/opensearch.module';
import { AgentsModule } from './agents/agents.module';
import { AuthModule } from './auth/auth.module';
import { AuthGuard } from './auth/auth.guard';
import { RolesGuard } from './auth/roles.guard';
import { ComponentsModule } from './components/components.module';
import { StorageModule } from './storage/storage.module';
import { SecretsModule } from './secrets/secrets.module';
import { TraceModule } from './trace/trace.module';
import { WorkflowsModule } from './workflows/workflows.module';
import { TestingSupportModule } from './testing/testing.module';
import { IntegrationsModule } from './integrations/integrations.module';
import { SchedulesModule } from './schedules/schedules.module';
import { AnalyticsModule } from './analytics/analytics.module';
import { McpModule } from './mcp/mcp.module';
import { StudioMcpModule } from './studio-mcp/studio-mcp.module';
import { AuditModule } from './audit/audit.module';
import { ApiKeysModule } from './api-keys/api-keys.module';
import { WebhooksModule } from './webhooks/webhooks.module';
import { HumanInputsModule } from './human-inputs/human-inputs.module';
import { McpServersModule } from './mcp-servers/mcp-servers.module';
import { McpGroupsModule } from './mcp-groups/mcp-groups.module';
import { TemplatesModule } from './templates/templates.module';
import { UserPreferencesModule } from './user-preferences/user-preferences.module';
const coreModules = [
AgentsModule,
AnalyticsModule,
AuthModule,
WorkflowsModule,
TraceModule,
ComponentsModule,
StorageModule,
SecretsModule,
IntegrationsModule,
SchedulesModule,
ApiKeysModule,
WebhooksModule,
HumanInputsModule,
McpServersModule,
McpGroupsModule,
McpModule,
StudioMcpModule,
TemplatesModule,
AuditModule,
UserPreferencesModule,
];
const testingModules = process.env.NODE_ENV === 'production' ? [] : [TestingSupportModule];
function getEnvFilePaths(): string[] {
// In multi-instance dev, each instance has its own env file under:
// .instances/instance-N/backend.env
// Backends run with cwd=backend/, so repo root is `..`.
const instance = process.env.SHIPSEC_INSTANCE;
if (instance) {
// Use only the instance env file. In multi-instance dev the workspace `.env` contains
// a default DATABASE_URL, and dotenv does not override already-set env vars; mixing
// would collapse isolation.
return [join(process.cwd(), '..', '.instances', `instance-${instance}`, 'backend.env')];
}
return ['.env', '../.env'];
}
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
envFilePath: getEnvFilePaths(),
load: [authConfig, opensearchConfig],
validate: validateBackendEnv,
}),
ThrottlerModule.forRootAsync({
useFactory: () => {
const redisUrl = process.env.REDIS_URL;
return {
throttlers: [
{
name: 'default',
ttl: seconds(60), // 60 seconds
limit: 100, // 100 requests per minute
},
],
storage: redisUrl ? new ThrottlerStorageRedisService(new Redis(redisUrl)) : undefined, // Falls back to in-memory storage if Redis not configured
};
},
}),
OpenSearchModule,
...coreModules,
...testingModules,
],
controllers: [AppController],
providers: [
AppService,
{
provide: APP_GUARD,
useClass: AuthGuard,
},
{
provide: APP_GUARD,
useClass: RolesGuard,
},
{
provide: APP_GUARD,
useClass: ThrottlerGuard,
},
],
})
export class AppModule {}