49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { Module } from '@nestjs/common';
|
||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||
import { ScheduleModule } from '@nestjs/schedule';
|
||
import { EvolutionModule } from './evolution/evolution.module';
|
||
import { AdminModule } from './admin/admin.module';
|
||
import { HealthModule } from './health/health.module';
|
||
import { AnalyticsModule } from './analytics/analytics.module';
|
||
|
||
@Module({
|
||
imports: [
|
||
// 配置模块
|
||
ConfigModule.forRoot({
|
||
isGlobal: true,
|
||
envFilePath: ['.env.local', '.env'],
|
||
}),
|
||
|
||
// 定时任务模块
|
||
ScheduleModule.forRoot(),
|
||
|
||
// 数据库连接
|
||
TypeOrmModule.forRootAsync({
|
||
imports: [ConfigModule],
|
||
inject: [ConfigService],
|
||
useFactory: (config: ConfigService) => ({
|
||
type: 'postgres',
|
||
host: config.get('POSTGRES_HOST', 'localhost'),
|
||
port: config.get<number>('POSTGRES_PORT', 5432),
|
||
username: config.get('POSTGRES_USER', 'postgres'),
|
||
password: config.get('POSTGRES_PASSWORD'),
|
||
database: config.get('POSTGRES_DB', 'iconsulting'),
|
||
autoLoadEntities: true,
|
||
// 禁用synchronize,使用init-db.sql初始化schema
|
||
synchronize: false,
|
||
logging: config.get('NODE_ENV') === 'development',
|
||
}),
|
||
}),
|
||
|
||
// Health check
|
||
HealthModule,
|
||
|
||
// 功能模块
|
||
EvolutionModule,
|
||
AdminModule,
|
||
AnalyticsModule,
|
||
],
|
||
})
|
||
export class AppModule {}
|