diff --git a/components/BodyParserJSON.coffee b/components/BodyParserJSON.coffee new file mode 100644 index 0000000..44adb64 --- /dev/null +++ b/components/BodyParserJSON.coffee @@ -0,0 +1,35 @@ +noflo = require 'noflo' +bodyParser = require 'body-parser' + +exports.getComponent = -> + c = new noflo.Component + c.description = 'Express body parser middleware' + c.inPorts.add 'app', + datatype: 'object' + type: 'http://expressjs.com/4x/api.html#app' + description: 'Express Application or Router' + required: true + c.inPorts.add 'limit', + datatype: 'string' + description: 'Size limit for parsed body' + required: false + default: '1mb' + c.outPorts.add 'app', + datatype: 'object' + type: 'http://expressjs.com/4x/api.html#app' + description: 'Express Application or Router' + required: true + + c.forwardBrackets = + app: ['app'] + + c.process (input, output) -> + return unless input.hasData 'app' + limit = if input.hasData('limit') then input.getData('limit') else '1mb' + + app = input.getData 'app' + app.use bodyParser.json + limit: limit + + output.sendDone + app: app diff --git a/package.json b/package.json index fe5cfc9..bbbb60d 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ }, "license": "BSD-2-Clause", "dependencies": { + "body-parser": "^1.17.1", "coffee-script": "^1.12.1", "express": "^4.14.0", "noflo": "0.x >= 0.8",