forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.module.ts
More file actions
69 lines (68 loc) 路 2.35 KB
/
Copy pathapp.module.ts
File metadata and controls
69 lines (68 loc) 路 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { APP_GUARD } from '@nestjs/core';
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
import { WinstonModule } from 'nest-winston';
import { DatabaseModule } from './database/database.module';
import { GeoModule } from './geo/geo.module';
import { IpfsModule } from './ipfs/ipfs.module';
import { SorobanModule } from './soroban/soroban.module';
import { GistsModule } from './gists/gists.module';
import { HealthModule } from './health/health.module';
import { MetricsModule } from './metrics/metrics.module';
import { ShutdownModule } from './common/shutdown/shutdown.module';
import { envValidationSchema } from './config/env.validation';
import { CorrelationIdMiddleware } from './common/middleware/correlation-id.middleware';
import { InFlightRequestMiddleware } from './common/shutdown/in-flight.middleware';
import { buildWinstonOptions } from './common/logger/winston.config';
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
validationSchema: envValidationSchema,
validationOptions: { abortEarly: false },
}),
WinstonModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) =>
buildWinstonOptions(
config.get<string>('NODE_ENV', 'development'),
config.get<string>('LOG_DIR', 'logs'),
),
}),
ThrottlerModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => [
{
ttl: config.get<number>('THROTTLE_TTL_MS', 60000),
limit: config.get<number>('THROTTLE_LIMIT', 10),
},
],
}),
DatabaseModule,
GeoModule,
IpfsModule,
SorobanModule,
GistsModule,
HealthModule,
MetricsModule,
ShutdownModule,
],
providers: [
{
provide: APP_GUARD,
useClass: ThrottlerGuard,
},
],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
// In-flight-request middleware must run before correlation-id so that
// every response (including 404s) is counted toward the drain window.
consumer
.apply(InFlightRequestMiddleware, CorrelationIdMiddleware)
.forRoutes('*');
}
}