This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add requireParameters config option, return 400 bad request if requir…
…ed parameter not found in query/body/paras
- Loading branch information
29decibel
committed
Mar 21, 2014
1 parent
7856aa2
commit 88c2e03
Showing
6 changed files
with
62 additions
and
4 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
_site | ||
_site | ||
node_modules |
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,16 @@ | ||
var g = require('dyson-generators'); | ||
|
||
module.exports = { | ||
path: '/requirepara', | ||
requireParameters: ["client_id"], | ||
template: { | ||
id: g.id, | ||
name: g.name, | ||
address: { | ||
city: g.address.city, | ||
zipUS: g.address.zipUS | ||
}, | ||
time: g.time.byQuarter, | ||
lorem: g.lorem.short, | ||
} | ||
}; |
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,22 @@ | ||
var _ = require('lodash'); | ||
|
||
module.exports = function(req, res, next){ | ||
var config = this, | ||
missingParameters = []; | ||
|
||
// check if it's need require parameters | ||
if (!_.isEmpty(config.requireParameters)) { | ||
_(config.requireParameters).forEach(function(p){ | ||
if (_.isEmpty(req.body[p]) && _.isEmpty(req.query[p])) { | ||
missingParameters.push(p); | ||
} | ||
}); | ||
|
||
// check missing parameters | ||
if (missingParameters.length > 0) { | ||
res.status(400).send({"error": "Required parameters(" + missingParameters.join(',') + ") not found."}); | ||
} | ||
} | ||
|
||
next(); | ||
}; |
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