Skip to content

Commit

Permalink
feat(vc-api): add access log (#187)
Browse files Browse the repository at this point in the history
* add morgan

* configure morgan access log
  • Loading branch information
jrhender committed Oct 13, 2023
1 parent 4c0eca3 commit d7769d5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 132 deletions.
4 changes: 3 additions & 1 deletion apps/vc-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
"@nestjs/axios": "^3.0.0",
"@nestjs/serve-static": "^4.0.0",
"joi": "^17.9.2",
"axios": "~1.4.0"
"axios": "~1.4.0",
"morgan": "~1.10.0",
"@types/morgan": "~1.9.6"
},
"devDependencies": {
"@nestjs/cli": "^10.1.0",
Expand Down
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);
}
}
175 changes: 46 additions & 129 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d7769d5

Please sign in to comment.