Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves parseJson middleware to its own file. This requires moving the join helper function that is used by parseJson and parseForm to a seperate file as well. This new file is forEachable.js and is to hold utility functions for working with forEachables.
- Loading branch information
Nathan
committed
Jun 19, 2013
1 parent
50a3157
commit 0a87796
Showing
3 changed files
with
35 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var q = require('./q'); | ||
|
||
exports.join = function (forEachable) { | ||
var body = ''; | ||
|
||
function appendChunk(chunk) { | ||
body += chunk; | ||
}; | ||
|
||
return q.when(forEachable.forEach(appendChunk), function () { | ||
return body; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var middleware = require('../middleware') | ||
, forEachable = require('../forEachable') | ||
, q = require('../q'); | ||
|
||
module.exports = middleware(function (req, nextApp) { | ||
var contentType = req.headers['content-type']; | ||
|
||
if (contentType && req.body) { | ||
if (contentType === 'application/json') { | ||
|
||
return q.when(forEachable.join(req.body), function success(body) { | ||
req.body = JSON.parse(body); | ||
|
||
return nextApp(req); | ||
}); | ||
} | ||
} | ||
|
||
return nextApp(req); | ||
}); |