-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (32 loc) · 909 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var concat = require("concat-stream");
module.exports = function(bodyParser){
return function(req, res, next){
try {
if(req.method === 'POST') {
if(req.headers["content-type"] && req.headers["content-type"].includes("application/json")){
bodyParser()(req, res, function () {
next();
});
}
else{
req.pipe(concat({}, function(data){
req.body = data.toString("utf8");
next();
}));
}
} else {
next();
}
} catch(error) {
next(error);
}
};
function isJsonString(str) {
try {
JSON.parse(str)
} catch (e) {
return false;
}
return true;
}
};