105 lines
3.3 KiB
TypeScript
105 lines
3.3 KiB
TypeScript
|
|
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 { CommonModule } from './common/common.module';
|
||
|
|
|
||
|
|
// 配置文件
|
||
|
|
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';
|
||
|
|
|
||
|
|
// 业务模块
|
||
|
|
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';
|
||
|
|
|
||
|
|
// 守卫
|
||
|
|
import { JwtAuthGuard } from './common/guards/jwt-auth.guard';
|
||
|
|
import { RolesGuard } from './common/guards/roles.guard';
|
||
|
|
|
||
|
|
@Module({
|
||
|
|
imports: [
|
||
|
|
// 配置模块
|
||
|
|
ConfigModule.forRoot({
|
||
|
|
isGlobal: true,
|
||
|
|
load: [appConfig, databaseConfig, jwtConfig, redisConfig, cacheConfig, performanceConfig],
|
||
|
|
envFilePath: [
|
||
|
|
`.env.${process.env.NODE_ENV || 'development'}`,
|
||
|
|
'.env.local',
|
||
|
|
'.env',
|
||
|
|
],
|
||
|
|
}),
|
||
|
|
|
||
|
|
// 数据库模块
|
||
|
|
TypeOrmModule.forRootAsync({
|
||
|
|
imports: [ConfigModule],
|
||
|
|
useFactory: (configService: ConfigService) => ({
|
||
|
|
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',
|
||
|
|
}),
|
||
|
|
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,
|
||
|
|
},
|
||
|
|
],
|
||
|
|
})
|
||
|
|
export class AppModule {}
|