Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add body parser middleware component #72

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions components/BodyParserJSON.coffee
Original file line number Diff line number Diff line change
@@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is race-prone, should use return if input.attached('limit').length and not input.hasData('limit').


app = input.getData 'app'
app.use bodyParser.json
limit: limit

output.sendDone
app: app
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down