Permalink
Browse files

Allow for namespace middleware to be called on all routes in that nam…

…espace.
  • Loading branch information...
ForbesLindesay committed Apr 12, 2012
1 parent de62676 commit be509ee287a82ac2a041d17041a2ee2b6566ba33
Showing with 11 additions and 2 deletions.
  1. +11 −2 index.js
View
@@ -23,8 +23,17 @@ var express = require('express')
* @api public
*/
-exports.namespace = function(path, fn){
+exports.namespace = function(){
+ var args = Array.prototype.slice.call(arguments)
+ , path = args.shift()
+ , fn = args.pop()
+ , self = this;
(this._ns = this._ns || []).push(path);
+
+ if(args.length){
+ self.all('/*', args);
+ }
+
fn.call(this);
this._ns.pop();
return this;
@@ -52,7 +61,7 @@ express.router.methods.concat(['del']).forEach(function(method){
, path = args.shift()
, fn = args.pop()
, self = this;
-
+ var middleware = this._ns_middleware;
this.namespace(path, function(){
var curr = this.currentNamespace;
args.forEach(function(fn){

0 comments on commit be509ee

Please sign in to comment.