2026-01-28 13:03:28 +08:00
|
|
|
import { Module } from "@nestjs/common";
|
|
|
|
|
import { ConfigModule, ConfigService } from "@nestjs/config";
|
|
|
|
|
import { TypeOrmModule } from "@nestjs/typeorm";
|
|
|
|
|
import { ScheduleModule } from "@nestjs/schedule";
|
|
|
|
|
import { APP_GUARD } from "@nestjs/core";
|
|
|
|
|
import { AppController } from "./app.controller";
|
|
|
|
|
import { AppService } from "./app.service";
|
|
|
|
|
import { ThrottlerModule, ThrottlerGuard } from "@nestjs/throttler";
|
2026-01-28 10:42:06 +08:00
|
|
|
|
|
|
|
|
// 公共模块
|
2026-01-28 13:03:28 +08:00
|
|
|
import { CommonModule } from "./common/common.module";
|
2026-01-28 10:42:06 +08:00
|
|
|
|
|
|
|
|
// 配置文件
|
2026-01-28 13:03:28 +08:00
|
|
|
import appConfig from "./config/app.config";
|
|
|
|
|
import databaseConfig from "./config/database.config";
|
|
|
|
|
import jwtConfig from "./config/jwt.config";
|
|
|
|
|
import redisConfig from "./config/redis.config";
|
|
|
|
|
import cacheConfig from "./config/cache.config";
|
|
|
|
|
import performanceConfig from "./config/performance.config";
|
2026-01-28 10:42:06 +08:00
|
|
|
|
|
|
|
|
// 业务模块
|
2026-01-28 13:03:28 +08:00
|
|
|
import { AuthModule } from "./modules/auth/auth.module";
|
|
|
|
|
import { UsersModule } from "./modules/users/users.module";
|
|
|
|
|
import { GroupsModule } from "./modules/groups/groups.module";
|
|
|
|
|
import { GamesModule } from "./modules/games/games.module";
|
|
|
|
|
import { AppointmentsModule } from "./modules/appointments/appointments.module";
|
|
|
|
|
import { LedgersModule } from "./modules/ledgers/ledgers.module";
|
|
|
|
|
import { SchedulesModule } from "./modules/schedules/schedules.module";
|
|
|
|
|
import { BlacklistModule } from "./modules/blacklist/blacklist.module";
|
|
|
|
|
import { HonorsModule } from "./modules/honors/honors.module";
|
|
|
|
|
import { AssetsModule } from "./modules/assets/assets.module";
|
|
|
|
|
import { PointsModule } from "./modules/points/points.module";
|
|
|
|
|
import { BetsModule } from "./modules/bets/bets.module";
|
2026-01-28 10:42:06 +08:00
|
|
|
|
|
|
|
|
// 守卫
|
2026-01-28 13:03:28 +08:00
|
|
|
import { JwtAuthGuard } from "./common/guards/jwt-auth.guard";
|
|
|
|
|
import { RolesGuard } from "./common/guards/roles.guard";
|
2026-01-28 10:42:06 +08:00
|
|
|
|
|
|
|
|
@Module({
|
|
|
|
|
imports: [
|
|
|
|
|
// 配置模块
|
|
|
|
|
ConfigModule.forRoot({
|
|
|
|
|
isGlobal: true,
|
2026-01-28 13:03:28 +08:00
|
|
|
load: [
|
|
|
|
|
appConfig,
|
|
|
|
|
databaseConfig,
|
|
|
|
|
jwtConfig,
|
|
|
|
|
redisConfig,
|
|
|
|
|
cacheConfig,
|
|
|
|
|
performanceConfig,
|
|
|
|
|
],
|
2026-01-28 10:42:06 +08:00
|
|
|
envFilePath: [
|
2026-01-28 13:03:28 +08:00
|
|
|
`.env.${process.env.NODE_ENV || "development"}`,
|
|
|
|
|
".env.local",
|
|
|
|
|
".env",
|
2026-01-28 10:42:06 +08:00
|
|
|
],
|
|
|
|
|
}),
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
// 速率限制模块(防止暴力破解)
|
|
|
|
|
ThrottlerModule.forRoot([
|
|
|
|
|
{
|
|
|
|
|
name: "short",
|
|
|
|
|
ttl: 1000, // 1秒
|
|
|
|
|
limit: 3, // 允许3次请求
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "medium",
|
|
|
|
|
ttl: 10000, // 10秒
|
|
|
|
|
limit: 20, // 允许20次请求
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "long",
|
|
|
|
|
ttl: 60000, // 1分钟
|
|
|
|
|
limit: 100, // 允许100次请求
|
|
|
|
|
},
|
|
|
|
|
]),
|
|
|
|
|
|
2026-01-28 10:42:06 +08:00
|
|
|
// 数据库模块
|
|
|
|
|
TypeOrmModule.forRootAsync({
|
|
|
|
|
imports: [ConfigModule],
|
|
|
|
|
useFactory: (configService: ConfigService) => ({
|
2026-01-28 13:03:28 +08:00
|
|
|
type: "mysql",
|
|
|
|
|
host: configService.get("database.host"),
|
|
|
|
|
port: configService.get("database.port"),
|
|
|
|
|
username: configService.get("database.username"),
|
|
|
|
|
password: configService.get("database.password"),
|
|
|
|
|
database: configService.get("database.database"),
|
|
|
|
|
entities: [__dirname + "/**/*.entity{.ts,.js}"],
|
|
|
|
|
synchronize: configService.get("database.synchronize"),
|
|
|
|
|
logging: configService.get("database.logging"),
|
|
|
|
|
timezone: "+08:00",
|
|
|
|
|
charset: "utf8mb4",
|
2026-01-28 10:42:06 +08:00
|
|
|
}),
|
|
|
|
|
inject: [ConfigService],
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
// 定时任务模块
|
|
|
|
|
ScheduleModule.forRoot(),
|
|
|
|
|
|
|
|
|
|
// 公共模块
|
|
|
|
|
CommonModule,
|
|
|
|
|
|
|
|
|
|
// 业务模块
|
|
|
|
|
AuthModule,
|
|
|
|
|
UsersModule,
|
|
|
|
|
GroupsModule,
|
|
|
|
|
GamesModule,
|
|
|
|
|
AppointmentsModule,
|
|
|
|
|
LedgersModule,
|
|
|
|
|
SchedulesModule,
|
|
|
|
|
BlacklistModule,
|
|
|
|
|
HonorsModule,
|
|
|
|
|
AssetsModule,
|
|
|
|
|
PointsModule,
|
|
|
|
|
BetsModule,
|
|
|
|
|
],
|
|
|
|
|
controllers: [AppController],
|
|
|
|
|
providers: [
|
|
|
|
|
AppService,
|
|
|
|
|
// 全局守卫
|
|
|
|
|
{
|
|
|
|
|
provide: APP_GUARD,
|
|
|
|
|
useClass: JwtAuthGuard,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
provide: APP_GUARD,
|
|
|
|
|
useClass: RolesGuard,
|
|
|
|
|
},
|
2026-01-28 13:03:28 +08:00
|
|
|
// 速率限制守卫
|
|
|
|
|
{
|
|
|
|
|
provide: APP_GUARD,
|
|
|
|
|
useClass: ThrottlerGuard,
|
|
|
|
|
},
|
2026-01-28 10:42:06 +08:00
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
export class AppModule {}
|