Nest throttler with nullcart-style default profile and upload override via throttleProfiles.
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigModule, ConfigService, registerAs } from '@nestjs/config';
|
|
import { APP_GUARD } from '@nestjs/core';
|
|
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { getAltchaConfig, getAppConfig, getPostgresConfig } from './config';
|
|
import { validate } from './config/validate';
|
|
import { AltchaModule } from './modules/altcha/AltchaModule';
|
|
import { HealthCheckModule } from './modules/healthCheck/HealthCheckModule';
|
|
import { StorageModule } from './modules/storage/StorageModule';
|
|
import { UploadModule } from './modules/upload/UploadModule';
|
|
import { Config } from './types/Config';
|
|
|
|
@Module({
|
|
imports: [
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
validate,
|
|
load: [
|
|
registerAs('postgres', getPostgresConfig),
|
|
registerAs('app', getAppConfig),
|
|
registerAs('altcha', getAltchaConfig)
|
|
]
|
|
}),
|
|
ThrottlerModule.forRootAsync({
|
|
inject: [ConfigService],
|
|
useFactory: (configService: ConfigService) => {
|
|
const { throttle } = configService.get('app') as Config['app'];
|
|
|
|
return {
|
|
throttlers: [
|
|
{
|
|
name: 'default',
|
|
ttl: throttle.ttlMs,
|
|
limit: throttle.limit
|
|
}
|
|
]
|
|
};
|
|
}
|
|
}),
|
|
TypeOrmModule.forRootAsync({
|
|
useFactory: (configService: ConfigService) => configService.get('postgres') as Config['postgres'],
|
|
inject: [ConfigService]
|
|
}),
|
|
HealthCheckModule,
|
|
AltchaModule,
|
|
StorageModule,
|
|
UploadModule
|
|
],
|
|
providers: [
|
|
{
|
|
provide: APP_GUARD,
|
|
useClass: ThrottlerGuard
|
|
}
|
|
]
|
|
})
|
|
export class AppModule {}
|