59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
|
|
|
|
import { RequestIdMiddleware } from './common/middleware/request-id.middleware';
|
|
import { HealthModule } from './health/health.module';
|
|
import { PrismaModule } from './prisma/prisma.module';
|
|
|
|
import { APP_GUARD } from '@nestjs/core';
|
|
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
|
|
import { LoggerModule } from 'nestjs-pino';
|
|
|
|
@Module({
|
|
imports: [
|
|
LoggerModule.forRoot({
|
|
pinoHttp: {
|
|
level: process.env['LOG_LEVEL'] ?? 'info',
|
|
transport:
|
|
process.env['NODE_ENV'] === 'development'
|
|
? {
|
|
target: 'pino-pretty',
|
|
options: {
|
|
colorize: true,
|
|
singleLine: true,
|
|
},
|
|
}
|
|
: undefined,
|
|
serializers: {
|
|
req: (req: { id?: string; method?: string; url?: string }) => ({
|
|
id: req.id,
|
|
method: req.method,
|
|
url: req.url,
|
|
}),
|
|
},
|
|
customProps: (req: { id?: string }) => ({
|
|
requestId: req.id,
|
|
}),
|
|
},
|
|
}),
|
|
ThrottlerModule.forRoot([
|
|
{
|
|
ttl: 60_000,
|
|
limit: 100,
|
|
},
|
|
]),
|
|
PrismaModule,
|
|
HealthModule,
|
|
],
|
|
providers: [
|
|
{
|
|
provide: APP_GUARD,
|
|
useClass: ThrottlerGuard,
|
|
},
|
|
],
|
|
})
|
|
export class AppModule implements NestModule {
|
|
configure(consumer: MiddlewareConsumer): void {
|
|
consumer.apply(RequestIdMiddleware).forRoutes('*');
|
|
}
|
|
}
|