78 lines
2.8 KiB
TypeScript
78 lines
2.8 KiB
TypeScript
import { Module } from "@nestjs/common";
|
||
import { APP_GUARD } from '@nestjs/core';
|
||
import { AppController } from "./app.controller";
|
||
import { AppService } from "./app.service";
|
||
import { DatabaseModule } from "./database/database.module";
|
||
import { UsersModule } from "./users/users.module";
|
||
import { ConfigModule } from '@nestjs/config';
|
||
import { ScheduleModule } from '@nestjs/schedule';
|
||
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
|
||
import { LoggerModule } from './common/logger/logger.module';
|
||
import { RedisModule, ThrottlerStorageRedisService } from './redis';
|
||
import { CheckinsModule } from './checkins/checkins.module';
|
||
import { AiCoachModule } from './ai-coach/ai-coach.module';
|
||
import { TrainingPlansModule } from './training-plans/training-plans.module';
|
||
import { ArticlesModule } from './articles/articles.module';
|
||
import { RecommendationsModule } from './recommendations/recommendations.module';
|
||
import { ActivityLogsModule } from './activity-logs/activity-logs.module';
|
||
import { ExercisesModule } from './exercises/exercises.module';
|
||
import { MoodCheckinsModule } from './mood-checkins/mood-checkins.module';
|
||
import { GoalsModule } from './goals/goals.module';
|
||
import { DietRecordsModule } from './diet-records/diet-records.module';
|
||
import { FoodLibraryModule } from './food-library/food-library.module';
|
||
import { WaterRecordsModule } from './water-records/water-records.module';
|
||
import { ChallengesModule } from './challenges/challenges.module';
|
||
import { PushNotificationsModule } from './push-notifications/push-notifications.module';
|
||
import { MedicationsModule } from './medications/medications.module';
|
||
import { HealthProfilesModule } from './health-profiles/health-profiles.module';
|
||
|
||
@Module({
|
||
imports: [
|
||
ConfigModule.forRoot({
|
||
isGlobal: true,
|
||
envFilePath: '.env',
|
||
}),
|
||
ScheduleModule.forRoot(),
|
||
// 限流模块必须在 RedisModule 之后导入,以确保 Redis 连接可用
|
||
RedisModule,
|
||
ThrottlerModule.forRootAsync({
|
||
useFactory: (throttlerStorage: ThrottlerStorageRedisService) => ({
|
||
throttlers: [{
|
||
ttl: 60000, // 时间窗口:60秒
|
||
limit: 100, // 每个时间窗口最多100个请求
|
||
}],
|
||
storage: throttlerStorage,
|
||
}),
|
||
inject: [ThrottlerStorageRedisService],
|
||
}),
|
||
LoggerModule,
|
||
DatabaseModule,
|
||
UsersModule,
|
||
CheckinsModule,
|
||
AiCoachModule,
|
||
TrainingPlansModule,
|
||
ArticlesModule,
|
||
RecommendationsModule,
|
||
ActivityLogsModule,
|
||
ExercisesModule,
|
||
MoodCheckinsModule,
|
||
GoalsModule,
|
||
DietRecordsModule,
|
||
FoodLibraryModule,
|
||
WaterRecordsModule,
|
||
ChallengesModule,
|
||
PushNotificationsModule,
|
||
MedicationsModule,
|
||
HealthProfilesModule,
|
||
],
|
||
controllers: [AppController],
|
||
providers: [
|
||
AppService,
|
||
{
|
||
provide: APP_GUARD,
|
||
useClass: ThrottlerGuard,
|
||
},
|
||
],
|
||
})
|
||
export class AppModule { }
|