chore:init project template
This commit is contained in:
49
src/app.module.ts
Normal file
49
src/app.module.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { Module, ValidationPipe } from '@nestjs/common'
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config'
|
||||
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core'
|
||||
import { JwtModule } from '@nestjs/jwt'
|
||||
import { ThrottlerGuard } from '@nestjs/throttler'
|
||||
import { AppController } from './app.controller.js'
|
||||
import { DbModule } from './core/db/db.module.js'
|
||||
import { HttpExceptionFilter } from './core/filter/http-exception.filter.js'
|
||||
import { JwtAuthGuard } from './core/guard/jwt.guard.js'
|
||||
import { TransformInterceptor } from './core/interceptor/transform.interceptor.js'
|
||||
import { LoggerModule } from './core/logger/logger.module.js'
|
||||
import { validationExceptionFactory } from './core/pipe/validation-exception.factory.js'
|
||||
import { RedisModule } from './core/redis/redis.module.js'
|
||||
import { ThrottlerModule } from './core/throttler/throttler.module.js'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({ isGlobal: true }),
|
||||
LoggerModule,
|
||||
DbModule,
|
||||
RedisModule,
|
||||
ThrottlerModule,
|
||||
JwtModule.registerAsync({
|
||||
global: true,
|
||||
inject: [ConfigService],
|
||||
useFactory: (config: ConfigService) => ({
|
||||
secret: config.getOrThrow<string>('JWT_SECRET'),
|
||||
signOptions: { expiresIn: config.get<string>('JWT_EXPIRES_IN', '7d') as `${number}${'s' | 'm' | 'h' | 'd' | 'w' | 'y'}` },
|
||||
}),
|
||||
}),
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [
|
||||
{ provide: APP_FILTER, useClass: HttpExceptionFilter },
|
||||
{ provide: APP_INTERCEPTOR, useClass: TransformInterceptor },
|
||||
{
|
||||
provide: APP_PIPE,
|
||||
useValue: new ValidationPipe({
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
transform: true,
|
||||
exceptionFactory: validationExceptionFactory,
|
||||
}),
|
||||
},
|
||||
{ provide: APP_GUARD, useClass: ThrottlerGuard },
|
||||
{ provide: APP_GUARD, useClass: JwtAuthGuard },
|
||||
],
|
||||
})
|
||||
export class AppModule { }
|
||||
Reference in New Issue
Block a user