chore(repo): restructure as monorepo with server and client workspaces
- move NestJS app into server/ subdirectory - add client/ React+TypeScript (Vite) app with Hello World - update docker-compose to build and run both services - add root package.json declaring npm workspaces - update .gitignore to cover node_modules and dist at all depths
This commit is contained in:
1 parent
afc4627353
commit
5cc16725fb
88 files changed
+12637
-405
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
NestInterceptor,
|
||||
} from "@nestjs/common";
|
||||
import { TraceLogger } from "../common/trace-logger";
|
||||
import type { Request, Response } from "express";
|
||||
import { Observable, tap } from "rxjs";
|
||||
|
||||
@Injectable()
|
||||
export class LoggingInterceptor implements NestInterceptor {
|
||||
private readonly logger = new TraceLogger(LoggingInterceptor.name);
|
||||
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
|
||||
const http = context.switchToHttp();
|
||||
const req = http.getRequest<Request>();
|
||||
const res = http.getResponse<Response>();
|
||||
const { method, url, body } = req;
|
||||
const start = Date.now();
|
||||
const bodyStr =
|
||||
body && Object.keys(body).length ? ` ${JSON.stringify(body)}` : "";
|
||||
|
||||
this.logger.debug(`→ ${method} ${url}${bodyStr}`);
|
||||
|
||||
return next.handle().pipe(
|
||||
tap((responseBody) => {
|
||||
const ms = Date.now() - start;
|
||||
const len =
|
||||
responseBody != null ? JSON.stringify(responseBody).length : 0;
|
||||
const lenStr = len > 0 ? ` [${len}b]` : "";
|
||||
this.logger.debug(
|
||||
`← ${method} ${url} ${res.statusCode} (${ms}ms)${lenStr}`,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user