/
bodyParser.js
executable file
·42 lines (31 loc) · 1010 Bytes
/
bodyParser.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
34
35
36
37
38
39
40
41
42
const bodyParser = require('koa-bodyparser');
const PathListCheck = require('pathListCheck');
function BodyParser() {
this.ignore = new PathListCheck();
// default limits are:
// formLimit: limit of the urlencoded body. If the body ends up being larger than this limit, a 413 error code is returned.
// Default is 56kb
// jsonLimit: limit of the json body.
// Default is 1mb
this.parser = bodyParser({
formLimit: '1mb', // 56kb is not enough for mandrill webhook which is urlencoded
jsonLimit: '1mb'
});
}
BodyParser.prototype.middleware = function() {
var self = this;
return function*(next) {
if (!self.ignore.check(this.path)) {
this.log.debug("bodyParser will parse");
await self.parser.call(this, next);
this.log.debug("bodyParser done parse");
} else {
this.log.debug("bodyParser skip");
}
await next;
};
};
exports.init = function(app) {
app.bodyParser = new BodyParser();
app.use(app.bodyParser.middleware());
};