Comparing version 0.5.4 to 0.5.5
var router = require('router'); | ||
var server = router(); | ||
@@ -18,13 +17,2 @@ | ||
var ns = server.namespace('ns'); | ||
ns.get('/', function(req, res) { | ||
res.writeHead(200); | ||
res.end('i am ns root'); | ||
}); | ||
ns.all(function(req, res) { | ||
res.writeHead(200); | ||
res.end('olla from namespace'); | ||
}); | ||
server.all(function(req, res) { | ||
@@ -31,0 +19,0 @@ res.writeHead(200); |
10
index.js
@@ -104,3 +104,3 @@ var http = require('http'); | ||
this.removeListener('request', this.route); | ||
return this.route; | ||
@@ -185,11 +185,3 @@ }; | ||
}; | ||
Router.prototype.namespace = Router.prototype.prefix = function(prefix) { | ||
var router = new Router(); | ||
prefix = '/'+prefix.replace(/^\//, '').replace(/\/$/, ''); | ||
this.all(prefix+'/*', '/{*}', router.route).all(prefix, '/', router.route); | ||
return router; | ||
}; | ||
Router.prototype._find = function(request, response) { | ||
@@ -196,0 +188,0 @@ var method = request.method; |
@@ -0,1 +1,9 @@ | ||
var decode = function(str) { | ||
try { | ||
return decodeURIComponent(str); | ||
} catch(err) { | ||
return str; | ||
} | ||
}; | ||
module.exports = function(pattern) { | ||
@@ -33,2 +41,3 @@ if (typeof pattern !== 'string') { // regex | ||
param = decode(param); | ||
map[k] = map[k] ? [].concat(map[k]).concat(param) : param; | ||
@@ -35,0 +44,0 @@ }); |
{ | ||
"name":"router", | ||
"version":"0.5.4", | ||
"version":"0.5.5", | ||
"description":"A lean and mean web router", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
8736
238