Files
plates-server/src/app.module.ts

78 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 { }