app.module.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // apps/box-app-api/src/app.module.ts
  2. import { Module } from '@nestjs/common';
  3. import { ConfigModule, ConfigService } from '@nestjs/config';
  4. import { ScheduleModule } from '@nestjs/schedule';
  5. import { APP_INTERCEPTOR, APP_FILTER } from '@nestjs/core';
  6. import { ResponseInterceptor } from '@box/common/interceptors/response.interceptor';
  7. import { HttpExceptionFilter } from '@box/common/filters/http-exception.filter';
  8. import { RedisCacheModule } from './redis/redis-cache.module';
  9. import { HealthModule } from './health/health.module';
  10. import { PrismaMongoModule } from './prisma/prisma-mongo.module';
  11. import { VideoModule } from './feature/video/video.module';
  12. import { AdModule } from './feature/ads/ad.module';
  13. import { HomepageModule } from './feature/homepage/homepage.module';
  14. import { SysParamsModule } from './feature/sys-params/sys-params.module';
  15. import { RedisModule } from '@box/db/redis/redis.module';
  16. import { RabbitmqModule } from './rabbitmq/rabbitmq.module';
  17. import { AuthModule } from './feature/auth/auth.module';
  18. import { RecommendationModule } from './feature/recommendation/recommendation.module';
  19. import path from 'path';
  20. @Module({
  21. imports: [
  22. // Global config, reuse .env + .env.app.dev at repo root
  23. ConfigModule.forRoot({
  24. isGlobal: true,
  25. envFilePath: [path.resolve(process.cwd(), '.env')],
  26. expandVariables: true,
  27. }),
  28. // Global Schedule module for CRON jobs
  29. ScheduleModule.forRoot(),
  30. // Global Redis module for RedisService
  31. RedisModule.forRootAsync({
  32. imports: [ConfigModule],
  33. inject: [ConfigService],
  34. useFactory: (configService: ConfigService) => ({
  35. host: configService.get<string>('REDIS_HOST') ?? '127.0.0.1',
  36. port: configService.get<number>('REDIS_PORT') ?? 6379,
  37. password: configService.get<string>('REDIS_PASSWORD'),
  38. db: configService.get<number>('REDIS_DB') ?? 0,
  39. keyPrefix: configService.get<string>('REDIS_KEY_PREFIX'),
  40. }),
  41. }),
  42. // RabbitMQ publisher for user login events
  43. RabbitmqModule,
  44. // Global Redis cache
  45. RedisCacheModule,
  46. // Mongo Prisma client for box_app DB (stub, to wire real client later)
  47. PrismaMongoModule,
  48. // Simple health endpoint
  49. AuthModule,
  50. HealthModule,
  51. VideoModule,
  52. AdModule,
  53. // RecommendationModule,
  54. HomepageModule,
  55. SysParamsModule,
  56. ],
  57. providers: [
  58. {
  59. provide: APP_INTERCEPTOR,
  60. useClass: ResponseInterceptor,
  61. },
  62. {
  63. provide: APP_FILTER,
  64. useClass: HttpExceptionFilter,
  65. },
  66. ],
  67. })
  68. export class AppModule {}