51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { AppController } from './app.controller';
|
|
import { AppService } from './app.service';
|
|
import { UserEntity } from './user/entities/user.entity';
|
|
import { BannerEntity } from './banner/entities/banner.entity';
|
|
import { AuthEntity } from './auth/entities/auth.entity';
|
|
import { UserModule } from './user/user.module';
|
|
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
|
|
import { BannerModule } from './banner/banner.module';
|
|
import { OssModule } from './oss/oss.module';
|
|
import { AuthModule } from './auth/auth.module';
|
|
import { APP_GUARD } from '@nestjs/core';
|
|
import { jwtAuthGuard } from './jwt/jwt-auth.grard';
|
|
import { getConfig } from 'config/configuration';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
|
|
const ENTITIES = [UserEntity, BannerEntity, AuthEntity];
|
|
|
|
const MODULE = [UserModule, BannerModule, OssModule, AuthModule];
|
|
|
|
@Module({
|
|
imports: [
|
|
ConfigModule.forRoot({
|
|
cache: true,
|
|
load: [getConfig],
|
|
isGlobal: true,
|
|
}),
|
|
TypeOrmModule.forRootAsync({
|
|
imports: [ConfigModule],
|
|
inject: [ConfigService],
|
|
useFactory: (config: ConfigService) => {
|
|
return {
|
|
type: 'mysql',
|
|
entities: ENTITIES,
|
|
...config.get('db.mysql'),
|
|
} as TypeOrmModuleOptions;
|
|
},
|
|
}),
|
|
...MODULE,
|
|
],
|
|
controllers: [AppController],
|
|
providers: [
|
|
AppService,
|
|
{
|
|
provide: APP_GUARD,
|
|
useClass: jwtAuthGuard,
|
|
},
|
|
],
|
|
})
|
|
export class AppModule {}
|