From c03a450d9b952e1463ae2609303029e317ff5da2 Mon Sep 17 00:00:00 2001 From: Max Ogden Date: Sat, 15 Oct 2011 18:43:45 -0700 Subject: [PATCH] simplify proxytable path segment rewrite logic --- lib/node-http-proxy/proxy-table.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/node-http-proxy/proxy-table.js b/lib/node-http-proxy/proxy-table.js index 4ab6690..d93f082 100644 --- a/lib/node-http-proxy/proxy-table.js +++ b/lib/node-http-proxy/proxy-table.js @@ -138,14 +138,12 @@ ProxyTable.prototype.getProxyLocation = function (req) { var route = this.routes[i]; if (target.match(route.route)) { - var segments = route.path.split('/'); + var pathSegments = route.path.split('/'); - if (segments.length > 0) { - var lastSegment = new RegExp("/" + segments[segments.length - 1] + "$"); - - if(req.url.match(lastSegment)) { - req.url = req.url.replace(lastSegment, '/'); - } + if (pathSegments.length > 0) { + // don't include the proxytable path segments in the proxied request url + pathSegments = new RegExp("/" + pathSegments.slice(1).join('/')); + req.url = req.url.replace(pathSegments, ''); } var location = route.target.split(':'),