-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
You can now add middleware to all routing functions
- Loading branch information
Showing
2 changed files
with
30 additions
and
23 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 |
---|---|---|
@@ -1,23 +1,28 @@ | ||
exports.route = function(routes, app) { | ||
var args, func, funcs, path, type, _results; | ||
funcs = { | ||
post: app.post, | ||
get: app.get, | ||
all: app.all | ||
(function() { | ||
exports.route = function(routes, app, middleware) { | ||
var args, func, funcs, path, type, _results; | ||
funcs = { | ||
post: app.post, | ||
get: app.get, | ||
all: app.all | ||
}; | ||
_results = []; | ||
for (type in funcs) { | ||
func = funcs[type]; | ||
_results.push((function() { | ||
var _results2; | ||
_results2 = []; | ||
for (path in routes[type]) { | ||
args = routes[type][path]; | ||
if (middleware) { | ||
args.unshift(middleware); | ||
} | ||
args.unshift(path); | ||
_results2.push(func.apply(app, args)); | ||
} | ||
return _results2; | ||
})()); | ||
} | ||
return _results; | ||
}; | ||
_results = []; | ||
for (type in funcs) { | ||
func = funcs[type]; | ||
_results.push((function() { | ||
var _results2; | ||
_results2 = []; | ||
for (path in routes[type]) { | ||
args = routes[type][path]; | ||
args.unshift(path); | ||
_results2.push(func.apply(app, args)); | ||
} | ||
return _results2; | ||
})()); | ||
} | ||
return _results; | ||
}; | ||
}).call(this); |