@belmonddev/catch-request-express-middleware 1.0.1 → 1.1.0
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 +18 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -97,7 +97,7 @@ const overrideHttpModule = (httpModule, requestSentCb) => {
|
|
|
97
97
|
});
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
-
const
|
|
100
|
+
const callReceivedCbs = (req, res, requestReceivedCb) => {
|
|
101
101
|
const responseCb = requestReceivedCb({
|
|
102
102
|
headers: req.headers,
|
|
103
103
|
method: req.method,
|
|
@@ -117,6 +117,7 @@ const catchExpressReceivedRequest = (req, res, requestReceivedCb) => {
|
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
req.socket.setMaxListeners(100);
|
|
120
121
|
req.socket.on('close', () => {
|
|
121
122
|
responseCb({
|
|
122
123
|
headers: res.getHeaders(),
|
|
@@ -130,6 +131,22 @@ const catchExpressReceivedRequest = (req, res, requestReceivedCb) => {
|
|
|
130
131
|
}
|
|
131
132
|
};
|
|
132
133
|
|
|
134
|
+
const catchExpressReceivedRequest = (req, res, requestReceivedCb) => {
|
|
135
|
+
if (req.headers['content-type'] !== 'application/json') {
|
|
136
|
+
let body = '';
|
|
137
|
+
req.on('data', function (data) {
|
|
138
|
+
body += data;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
req.on('end', function () {
|
|
142
|
+
req.body = body;
|
|
143
|
+
callReceivedCbs(req, res, requestReceivedCb);
|
|
144
|
+
});
|
|
145
|
+
} else {
|
|
146
|
+
callReceivedCbs(req, res, requestReceivedCb);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
133
150
|
const catchRequestExpressMiddleware = (requestReceivedCb, requestSentCb) => {
|
|
134
151
|
overrideHttpModule(http, requestSentCb);
|
|
135
152
|
overrideHttpModule(https, requestSentCb);
|