@belmonddev/catch-request-express-middleware 1.2.0 → 1.2.2
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/index.js +13 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -51,7 +51,7 @@ const catchHttpResponse = (reqObject, responseCb) => {
|
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
53
|
} else {
|
|
54
|
-
const stringBody = chunks.toString('utf8');
|
|
54
|
+
const stringBody = chunks.map((c) => c.toString('utf8')).join('');
|
|
55
55
|
responseCb({
|
|
56
56
|
...responseObj,
|
|
57
57
|
body: /application\/json;?.*?$/.test(
|
|
@@ -113,7 +113,7 @@ const callReceivedCbs = (req, res, requestReceivedCb) => {
|
|
|
113
113
|
headers: req.headers,
|
|
114
114
|
method: req.method,
|
|
115
115
|
host: req.headers.host,
|
|
116
|
-
pathname: req.
|
|
116
|
+
pathname: req._parsedUrl.pathname,
|
|
117
117
|
params: req.params,
|
|
118
118
|
query: req.query,
|
|
119
119
|
body: req.body,
|
|
@@ -162,11 +162,18 @@ const catchExpressReceivedRequest = (req, res, requestReceivedCb) => {
|
|
|
162
162
|
}
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
-
const catchRequestExpressMiddleware = (
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
const catchRequestExpressMiddleware = (
|
|
166
|
+
requestReceivedCb = null,
|
|
167
|
+
requestSentCb = null
|
|
168
|
+
) => {
|
|
169
|
+
if (requestSentCb) {
|
|
170
|
+
overrideHttpModule(http, requestSentCb);
|
|
171
|
+
overrideHttpModule(https, requestSentCb);
|
|
172
|
+
}
|
|
168
173
|
return (req, res, next) => {
|
|
169
|
-
|
|
174
|
+
if (requestReceivedCb) {
|
|
175
|
+
catchExpressReceivedRequest(req, res, requestReceivedCb);
|
|
176
|
+
}
|
|
170
177
|
next();
|
|
171
178
|
};
|
|
172
179
|
};
|