Browse files

issue #1 fixed

  • Loading branch information...
1 parent 2b57bc4 commit a19680440c5b69f2206ae251530cc385b8ac1af0 @vdemedes committed Apr 4, 2012
Showing with 12 additions and 8 deletions.
  1. +4 −2 lib/route66.coffee
  2. +6 −4 lib/route66.js
  3. +2 −2 package.json
View
6 lib/route66.coffee
@@ -12,8 +12,10 @@ Route66 = (req, res, next) -> # function, that we are pushing to our connect mid
break if i >= values.length
req.params[route.params[i]] = values[i] # getting key and value and setting them
i++
- return async.forEachSeries route.functions, (fn, nextFn) -> # calling functions
+ functions = route.functions
+ return async.forEachSeries functions, (fn, nextFn) -> # calling functions
fn(req, res, nextFn)
+ do nextFn if functions.length is 0 # we should end this sometime
, ->
Route66.addRoute = (method, match, functions) -> # generic method for adding routes
@@ -28,7 +30,7 @@ Route66.addRoute = (method, match, functions) -> # generic method for adding rou
routes[method].push
match: new RegExp '^' + match.replace(/\//g, '\\/?').replace(/\:([A-Za-z_]+)(\?)?\/?/g, '([A-Za-z0-9_]+)$2') + '$' # making RegExp from string
params: params
- functions: if functions.length? then functions else toArray(functions).slice 1
+ functions: if functions instanceof Array then functions else toArray(functions).slice 1
do Route66.sort
toArray = (object) ->
View
10 lib/route66.js
@@ -5,7 +5,7 @@ async = require('async');
url = require('url');
Route66 = function(req, res, next) {
- var i, requestUrl, route, values, _i, _len, _ref;
+ var functions, i, requestUrl, route, values, _i, _len, _ref;
_ref = routes[req.method.toLowerCase()];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
route = _ref[_i];
@@ -19,8 +19,10 @@ Route66 = function(req, res, next) {
req.params[route.params[i]] = values[i];
i++;
}
- return async.forEachSeries(route.functions, function(fn, nextFn) {
- return fn(req, res, nextFn);
+ functions = route.functions;
+ return async.forEachSeries(functions, function(fn, nextFn) {
+ fn(req, res, nextFn);
+ if (functions.length === 0) return nextFn();
}, function() {});
}
}
@@ -41,7 +43,7 @@ Route66.addRoute = function(method, match, functions) {
routes[method].push({
match: new RegExp('^' + match.replace(/\//g, '\\/?').replace(/\:([A-Za-z_]+)(\?)?\/?/g, '([A-Za-z0-9_]+)$2') + '$'),
params: params,
- functions: functions.length != null ? functions : toArray(functions).slice(1)
+ functions: functions instanceof Array ? functions : toArray(functions).slice(1)
});
return Route66.sort();
};
View
4 package.json
@@ -1,6 +1,6 @@
{
"name": "route66",
- "version": "0.1.8",
+ "version": "0.1.9",
"author": "Vadim Demedes <sbioko@gmail.com>",
"description": "Routing functionality/middleware for Connect 2.0",
"main": "./index.js",
@@ -14,7 +14,7 @@
"node": ">=0.4"
},
"devDependencies": {
- "connect": "2.0.2"
+ "connect": "2.0.3"
},
"dependencies": {
"async": "*"

0 comments on commit a196804

Please sign in to comment.