Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved param() retval logic to Router#param()

  • Loading branch information...
commit d6ef90d98dce6cc54b2d6f070079772eede96f91 1 parent 85df59a
@tj tj authored
Showing with 15 additions and 9 deletions.
  1. +0 −1  lib/http.js
  2. +15 −8 lib/router/index.js
View
1  lib/http.js
@@ -532,4 +532,3 @@ app.all = function(path){
app.del = app.delete;
-
View
23 lib/router/index.js
@@ -54,6 +54,20 @@ function Router(app) {
*/
Router.prototype.param = function(name, fn){
+ var callback = fn;
+
+ if (fn.length < 3) {
+ fn = function(req, res, next){
+ var val = req.params[name];
+ val = req.params[name] = callback(val);
+ if (invalidParamReturnValue(val)) {
+ next('route');
+ } else {
+ next();
+ }
+ };
+ }
+
this.params[name] = fn;
return this;
};
@@ -193,13 +207,6 @@ Router.prototype._dispatch = function(req, res, next){
nextRoute();
} else if (err) {
next(err);
- } else if (fn && fn.length < 3) {
- ret = req.params[key] = fn(val);
- if (invalidParamReturnValue(ret)) {
- nextRoute();
- } else {
- param();
- }
} else if (fn) {
fn(req, res, param, val);
} else if (key) {
@@ -380,4 +387,4 @@ function invalidParamReturnValue(val){
return null == val
|| false === val
|| ('number' == typeof val && isNaN(val));
-};
+};
Please sign in to comment.
Something went wrong with that request. Please try again.