@centeredgesoft/runtime-mock-routes 2.10.2 → 2.10.3
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/build/src/appV2.js +15 -7
- package/package.json +1 -1
- package/src/appV2.ts +19 -8
package/build/src/appV2.js
CHANGED
|
@@ -103,19 +103,26 @@ const appFactory = (runtimeCollection) => {
|
|
|
103
103
|
if (process.env.LOG_MOCK_REQUESTS === 'true') {
|
|
104
104
|
const logger = api_logs_1.logs.getLogger('mock-requests-logger');
|
|
105
105
|
app.use((req, res, next) => {
|
|
106
|
-
|
|
106
|
+
let severity = api_logs_1.SeverityNumber.INFO;
|
|
107
|
+
let severityText = 'INFO';
|
|
108
|
+
// Log root requests as trace
|
|
109
|
+
if (req.path === '/') {
|
|
110
|
+
severity = api_logs_1.SeverityNumber.TRACE;
|
|
111
|
+
severityText = 'TRACE';
|
|
112
|
+
}
|
|
113
|
+
// Log the request
|
|
107
114
|
logger.emit({
|
|
108
|
-
severityNumber:
|
|
109
|
-
severityText:
|
|
115
|
+
severityNumber: severity,
|
|
116
|
+
severityText: severityText,
|
|
110
117
|
body: `Request ${req.path}`,
|
|
111
118
|
attributes: {
|
|
112
|
-
'http.headers': req.headers,
|
|
113
119
|
'http.method': req.method,
|
|
114
120
|
'http.url': req.url,
|
|
115
121
|
'http.request_body': req.body,
|
|
122
|
+
'http.request_headers': req.headers,
|
|
116
123
|
}
|
|
117
124
|
});
|
|
118
|
-
//
|
|
125
|
+
// Log the response
|
|
119
126
|
const originalSend = res.send;
|
|
120
127
|
let firstSend = true;
|
|
121
128
|
res.send = function (body) {
|
|
@@ -123,14 +130,15 @@ const appFactory = (runtimeCollection) => {
|
|
|
123
130
|
// For some reason send gets called twice per request, this ensures we only log once
|
|
124
131
|
firstSend = false;
|
|
125
132
|
logger.emit({
|
|
126
|
-
severityNumber:
|
|
127
|
-
severityText:
|
|
133
|
+
severityNumber: severity,
|
|
134
|
+
severityText: severityText,
|
|
128
135
|
body: `Response ${req.path}`,
|
|
129
136
|
attributes: {
|
|
130
137
|
'http.status_code': res.statusCode,
|
|
131
138
|
'http.method': req.method,
|
|
132
139
|
'http.url': req.url,
|
|
133
140
|
'http.response_body': body,
|
|
141
|
+
'http.response_headers': res.getHeaders()
|
|
134
142
|
}
|
|
135
143
|
});
|
|
136
144
|
}
|
package/package.json
CHANGED
package/src/appV2.ts
CHANGED
|
@@ -121,20 +121,30 @@ export const appFactory = (runtimeCollection?: RuntimeRequestCollection) => {
|
|
|
121
121
|
const logger = logs.getLogger('mock-requests-logger');
|
|
122
122
|
|
|
123
123
|
app.use((req, res, next) => {
|
|
124
|
-
|
|
124
|
+
|
|
125
|
+
let severity = SeverityNumber.INFO;
|
|
126
|
+
let severityText = 'INFO';
|
|
127
|
+
|
|
128
|
+
// Log root requests as trace
|
|
129
|
+
if (req.path === '/') {
|
|
130
|
+
severity = SeverityNumber.TRACE;
|
|
131
|
+
severityText = 'TRACE';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Log the request
|
|
125
135
|
logger.emit({
|
|
126
|
-
severityNumber:
|
|
127
|
-
severityText:
|
|
136
|
+
severityNumber: severity,
|
|
137
|
+
severityText: severityText,
|
|
128
138
|
body: `Request ${req.path}`,
|
|
129
139
|
attributes: {
|
|
130
|
-
'http.headers': req.headers,
|
|
131
140
|
'http.method': req.method,
|
|
132
141
|
'http.url': req.url,
|
|
133
142
|
'http.request_body': req.body,
|
|
143
|
+
'http.request_headers': req.headers,
|
|
134
144
|
}
|
|
135
145
|
});
|
|
136
146
|
|
|
137
|
-
//
|
|
147
|
+
// Log the response
|
|
138
148
|
const originalSend = res.send;
|
|
139
149
|
let firstSend = true;
|
|
140
150
|
res.send = function (body) {
|
|
@@ -143,14 +153,15 @@ export const appFactory = (runtimeCollection?: RuntimeRequestCollection) => {
|
|
|
143
153
|
firstSend = false;
|
|
144
154
|
|
|
145
155
|
logger.emit({
|
|
146
|
-
severityNumber:
|
|
147
|
-
severityText:
|
|
156
|
+
severityNumber: severity,
|
|
157
|
+
severityText: severityText,
|
|
148
158
|
body: `Response ${req.path}`,
|
|
149
159
|
attributes: {
|
|
150
160
|
'http.status_code': res.statusCode,
|
|
151
161
|
'http.method': req.method,
|
|
152
162
|
'http.url': req.url,
|
|
153
163
|
'http.response_body': body,
|
|
164
|
+
'http.response_headers': res.getHeaders()
|
|
154
165
|
}
|
|
155
166
|
});
|
|
156
167
|
}
|
|
@@ -305,7 +316,7 @@ export const appFactory = (runtimeCollection?: RuntimeRequestCollection) => {
|
|
|
305
316
|
app.put(/\/.*/, catchAllHandler);
|
|
306
317
|
app.patch(/\/.*/, catchAllHandler);
|
|
307
318
|
app.delete(/\/.*/, catchAllHandler);
|
|
308
|
-
|
|
319
|
+
|
|
309
320
|
Object.defineProperty(app, 'runtimeRequestCollection', {
|
|
310
321
|
get: () => {
|
|
311
322
|
return cloneDeep(runtimeRequestCollection);
|