Skip to content

Commit a918845

Browse files
committed
Using concat stream to process body
1 parent 78af80f commit a918845

3 files changed

Lines changed: 66 additions & 0 deletions

File tree

index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@ const morgan = require('morgan');
33
var app = express()
44
const os = require('os');
55
const jwt = require('jsonwebtoken');
6+
var concat = require('concat-stream');
67

78
app.set('json spaces', 2);
89

910
app.use(morgan('combined'));
1011

12+
app.use(function(req, res, next){
13+
req.pipe(concat(function(data){
14+
req.body = data.toString('utf8');
15+
next();
16+
}));
17+
});
18+
1119
app.all('*', (req, res) => {
1220
const echo = {
1321
path: req.path,

package-lock.json

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"node": ">=6.3.0"
1414
},
1515
"dependencies": {
16+
"concat-stream": "1.6.0",
1617
"express": "4.16.2",
1718
"jsonwebtoken": "8.1.0",
1819
"morgan": "1.9.0"

0 commit comments

Comments
 (0)