57 lines
2 KiB
TypeScript
57 lines
2 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { buildDeploymentRegistry } from '@lilith/service-registry';
|
|
import { HealthModule } from './modules/health/health.module';
|
|
import { IngestionModule } from './modules/ingestion/ingestion.module';
|
|
import { AnalyticsModule } from './modules/analytics/analytics.module';
|
|
|
|
// Build deployment registry - paths resolved via LILITH_PROJECT_ROOT env var
|
|
// Start services via ./run dev to ensure env var is set
|
|
const registry = buildDeploymentRegistry({
|
|
deploymentsPath: 'deployments/@domains',
|
|
sharedServicesPath: 'deployments/shared-services',
|
|
});
|
|
|
|
@Module({
|
|
imports: [
|
|
// Configuration
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
envFilePath: ['.env.local', '.env'],
|
|
}),
|
|
|
|
// Database — uses atlilith.www deployment's PostgreSQL
|
|
TypeOrmModule.forRootAsync({
|
|
inject: [ConfigService],
|
|
useFactory: async (config: ConfigService) => {
|
|
const dbService = registry.services.get('atlilith.www.postgresql');
|
|
|
|
if (!dbService?.localUrl) {
|
|
throw new Error('Service registry: atlilith.www.postgresql not found');
|
|
}
|
|
const dbUrl = new URL(dbService.localUrl);
|
|
const host = dbUrl.hostname;
|
|
const port = Number(dbUrl.port) || 25432;
|
|
|
|
return {
|
|
type: 'postgres' as const,
|
|
host,
|
|
port,
|
|
username: config.get<string>('DATABASE_POSTGRES_USER') ?? 'lilith',
|
|
password: config.get<string>('DATABASE_POSTGRES_PASSWORD') ?? 'lilith',
|
|
database: config.get<string>('DATABASE_POSTGRES_NAME') ?? 'lilith_share',
|
|
autoLoadEntities: true,
|
|
synchronize: config.get('NODE_ENV') !== 'production',
|
|
logging: config.get('NODE_ENV') !== 'production',
|
|
};
|
|
},
|
|
}),
|
|
|
|
// Feature modules
|
|
HealthModule,
|
|
IngestionModule,
|
|
AnalyticsModule,
|
|
],
|
|
})
|
|
export class AppModule {}
|