diff --git a/apps/vc-api/src/app.module.ts b/apps/vc-api/src/app.module.ts index fba48bfa..f286c1fa 100644 --- a/apps/vc-api/src/app.module.ts +++ b/apps/vc-api/src/app.module.ts @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -import { DynamicModule, Module } from '@nestjs/common'; +import { DynamicModule, MiddlewareConsumer, Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { KeyModule } from './key/key.module'; import { DidModule } from './did/did.module'; @@ -25,6 +25,7 @@ import { ServeStaticModule } from '@nestjs/serve-static'; import { join } from 'path'; import { SeederModule } from './seeder/seeder.module'; import { envVarsValidationSchema } from './config/env-vars-validation-schema'; +import { MorganMiddleware } from './morgan.middleware'; let config: DynamicModule; @@ -61,4 +62,8 @@ try { SeederModule ] }) -export class AppModule {} +export class AppModule { + configure(consumer: MiddlewareConsumer) { + consumer.apply(MorganMiddleware).forRoutes('*'); // This applies the middleware to all routes. You can narrow it down if needed. + } +} diff --git a/apps/vc-api/src/morgan.middleware.ts b/apps/vc-api/src/morgan.middleware.ts new file mode 100644 index 00000000..2d88f688 --- /dev/null +++ b/apps/vc-api/src/morgan.middleware.ts @@ -0,0 +1,9 @@ +import { Injectable, NestMiddleware } from '@nestjs/common'; +import * as morgan from 'morgan'; + +@Injectable() +export class MorganMiddleware implements NestMiddleware { + use(req: any, res: any, next: () => void) { + morgan('combined')(req, res, next); + } +}