This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for streams, and for not clobbering the express app outside of our scope
- Loading branch information
Robert
committed
Nov 14, 2015
1 parent
d03c58e
commit a2ed987
Showing
7 changed files
with
67 additions
and
16 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
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,46 @@ | ||
'use strict'; | ||
|
||
var qs = require('qs'); | ||
var getRawBody = require('raw-body'); | ||
|
||
function jsonParser(req, res, next) { | ||
// return bodyParser.json({ limit: '200kb' })(req, res, next); | ||
var type = req.headers && req.headers['content-type']; | ||
if (type !== 'application/json') { | ||
return next(); | ||
} | ||
getRawBody(req, function (err, string) { | ||
if (err) { | ||
return next(err); | ||
} | ||
try { | ||
req.body = JSON.parse(string.toString()); | ||
next(); | ||
} catch (e) { | ||
req.body = {}; | ||
next(); | ||
} | ||
}); | ||
} | ||
|
||
function formEncodedParser(req, res, next) { | ||
// return bodyParser.urlencoded({ extended: true })(req, res, next); | ||
// | ||
var type = req.headers && req.headers['content-type']; | ||
if (type !== 'application/x-www-form-urlencoded') { | ||
req.body = {}; | ||
return next(); | ||
} | ||
getRawBody(req, function (err, string) { | ||
if (err) { | ||
return next(err); | ||
} | ||
req.body = qs.parse(string.toString()) || {}; | ||
next(); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
jsonParser: jsonParser, | ||
formEncodedParser: formEncodedParser | ||
}; |
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
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
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