Permalink
Browse files

Version can now be found anywhere in the URL path

  • Loading branch information...
1 parent 8004895 commit 0c6c829ae8a2250753d3e3a40a11feeaefcfc312 @serby committed May 30, 2012
Showing with 3 additions and 9 deletions.
  1. +3 −9 lib/middleware/basic.js
View
@@ -43,21 +43,15 @@ module.exports = function(version) {
// Ensure version is a string
version = '' + version;
- var
- urlParts = url.parse(req.url),
- basename = path.basename(urlParts.pathname),
- dirname = path.dirname(urlParts.pathname),
- vPos = dirname.length - version.length;
+ var vPos = req.url.indexOf(version);
// If version isn't in path then move on.
- if (dirname.substring(vPos, vPos + version.length) !== version) {
+ if (vPos === -1) {
return next();
}
// Rebuild the URL without the version and set the request url.
- urlParts.pathname = path.join(dirname.substring(0, vPos), basename);
- req.url = url.format(urlParts);
-
+ req.url = req.url.substring(0, vPos - 1) + req.url.substring(vPos + version.length);
next();
}
};

0 comments on commit 0c6c829

Please sign in to comment.