Skip to content

Commit

Permalink
You can now add middleware to all routing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mckk committed Aug 6, 2011
1 parent add1363 commit 1bd0fd3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
4 changes: 3 additions & 1 deletion arouter.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.route = (routes, app) ->
exports.route = (routes, app, middleware) ->
funcs =
post: app.post
get: app.get
Expand All @@ -7,5 +7,7 @@ exports.route = (routes, app) ->
for type, func of funcs
for path of routes[type]
args = routes[type][path]
if middleware
args.unshift middleware
args.unshift path
func.apply app,args
49 changes: 27 additions & 22 deletions arouter.js
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);

0 comments on commit 1bd0fd3

Please sign in to comment.