| 61 | } |
| 62 | |
| 63 | export class App { |
| 64 | app: express.Application |
| 65 | nodesPool: NodesPool |
| 66 | abortControllerPool: AbortControllerPool |
| 67 | cachePool: CachePool |
| 68 | telemetry: Telemetry |
| 69 | rateLimiterManager: RateLimiterManager |
| 70 | AppDataSource: DataSource = getDataSource() |
| 71 | sseStreamer: SSEStreamer |
| 72 | identityManager: IdentityManager |
| 73 | metricsProvider: IMetricsProvider |
| 74 | queueManager: QueueManager |
| 75 | redisSubscriber: RedisEventSubscriber |
| 76 | usageCacheManager: UsageCacheManager |
| 77 | sessionStore: any |
| 78 | |
| 79 | constructor() { |
| 80 | this.app = express() |
| 81 | } |
| 82 | |
| 83 | async initDatabase() { |
| 84 | // Initialize database |
| 85 | try { |
| 86 | await this.AppDataSource.initialize() |
| 87 | logger.info('📦 [server]: Data Source initialized successfully') |
| 88 | |
| 89 | // Run Migrations Scripts |
| 90 | await this.AppDataSource.runMigrations({ transaction: 'each' }) |
| 91 | logger.info('🔄 [server]: Database migrations completed successfully') |
| 92 | |
| 93 | // Initialize Identity Manager |
| 94 | this.identityManager = await IdentityManager.getInstance() |
| 95 | logger.info('🔐 [server]: Identity Manager initialized successfully') |
| 96 | |
| 97 | // Initialize nodes pool |
| 98 | this.nodesPool = new NodesPool() |
| 99 | await this.nodesPool.initialize() |
| 100 | logger.info('🔧 [server]: Nodes pool initialized successfully') |
| 101 | |
| 102 | // Initialize abort controllers pool |
| 103 | this.abortControllerPool = new AbortControllerPool() |
| 104 | logger.info('⏹️ [server]: Abort controllers pool initialized successfully') |
| 105 | |
| 106 | // Initialize encryption key |
| 107 | await getEncryptionKey() |
| 108 | logger.info('🔑 [server]: Encryption key initialized successfully') |
| 109 | |
| 110 | // Initialize auth secrets (env → AWS Secrets Manager → filesystem) |
| 111 | await initAuthSecrets() |
| 112 | logger.info('🔐 [server]: Auth initialized successfully') |
| 113 | |
| 114 | // Initialize Rate Limit |
| 115 | this.rateLimiterManager = RateLimiterManager.getInstance() |
| 116 | await this.rateLimiterManager.initializeRateLimiters(await getDataSource().getRepository(ChatFlow).find()) |
| 117 | logger.info('🚦 [server]: Rate limiters initialized successfully') |
| 118 | |
| 119 | // Initialize cache pool |
| 120 | this.cachePool = new CachePool() |
nothing calls this directly
no test coverage detected