@belmonddev/catch-request-express-middleware 1.0.2 → 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.
Files changed (2) hide show
  1. package/index.js +17 -1
  2. 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 catchExpressReceivedRequest = (req, res, requestReceivedCb) => {
100
+ const callReceivedCbs = (req, res, requestReceivedCb) => {
101
101
  const responseCb = requestReceivedCb({
102
102
  headers: req.headers,
103
103
  method: req.method,
@@ -131,6 +131,22 @@ const catchExpressReceivedRequest = (req, res, requestReceivedCb) => {
131
131
  }
132
132
  };
133
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
+
134
150
  const catchRequestExpressMiddleware = (requestReceivedCb, requestSentCb) => {
135
151
  overrideHttpModule(http, requestSentCb);
136
152
  overrideHttpModule(https, requestSentCb);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@belmonddev/catch-request-express-middleware",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "nodemon -L --experimental-specifier-resolution=node ./src/index.js"