Skip to content

Commit

Permalink
configure morgan access log
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhender committed Oct 13, 2023
1 parent f96393f commit 4d97e04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions apps/vc-api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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';
Expand All @@ -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;

Expand Down Expand Up @@ -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.
}
}
9 changes: 9 additions & 0 deletions apps/vc-api/src/morgan.middleware.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 4d97e04

Please sign in to comment.