create-forgeon 0.1.31 → 0.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
|
|
2
|
-
import { Observable
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
3
|
import { ForgeonLoggerService } from './forgeon-logger.service';
|
|
4
4
|
import { LoggerConfigService } from './logger-config.service';
|
|
5
5
|
|
|
@@ -17,6 +17,7 @@ interface RequestLike {
|
|
|
17
17
|
|
|
18
18
|
interface ResponseLike {
|
|
19
19
|
statusCode?: number;
|
|
20
|
+
once?: (event: string, listener: () => void) => void;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
@Injectable()
|
|
@@ -46,30 +47,34 @@ export class ForgeonHttpLoggingInterceptor implements NestInterceptor {
|
|
|
46
47
|
request.requestId ?? this.readHeader(request.headers, this.loggerConfig.requestIdHeader);
|
|
47
48
|
const startedAt = Date.now();
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
50
|
+
if (typeof response.once === 'function') {
|
|
51
|
+
response.once('finish', () => {
|
|
52
|
+
this.logger.logHttpRequest({
|
|
53
|
+
method,
|
|
54
|
+
path,
|
|
55
|
+
statusCode: response.statusCode ?? 200,
|
|
56
|
+
durationMs: Date.now() - startedAt,
|
|
57
|
+
requestId,
|
|
58
|
+
ip,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
} else {
|
|
62
|
+
// Fallback for non-standard response mocks.
|
|
63
|
+
try {
|
|
64
|
+
this.logger.logHttpRequest({
|
|
65
|
+
method,
|
|
66
|
+
path,
|
|
67
|
+
statusCode: response.statusCode ?? 200,
|
|
68
|
+
durationMs: Date.now() - startedAt,
|
|
69
|
+
requestId,
|
|
70
|
+
ip,
|
|
71
|
+
});
|
|
72
|
+
} catch {
|
|
73
|
+
// no-op
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return next.handle();
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
private readHeader(headers: HeadersRecord | undefined, name: string): string | undefined {
|
|
@@ -87,4 +92,3 @@ export class ForgeonHttpLoggingInterceptor implements NestInterceptor {
|
|
|
87
92
|
return undefined;
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
|
-
|