From 63dfc7f1757fc9a1a9bceeb3b035e97be6504692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Ma=C5=82ecki?= Date: Sun, 18 Dec 2011 21:43:33 +0100 Subject: [PATCH] [fix] In routing proxy, match line beginning Previous approach failed in case of routing table like: { 'domain.com': 'localhost:9000', 'a.domain.com': 'localhost:9001' } without `hostnameOnly`. When routing request to `a.domain.com`, `RegExp` matched first entry (`domain.com`) and returned it. --- lib/node-http-proxy/proxy-table.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node-http-proxy/proxy-table.js b/lib/node-http-proxy/proxy-table.js index 0cdce50..9035ab8 100644 --- a/lib/node-http-proxy/proxy-table.js +++ b/lib/node-http-proxy/proxy-table.js @@ -97,7 +97,7 @@ ProxyTable.prototype.setRoutes = function (router) { this.routes = []; Object.keys(router).forEach(function (path) { - var route = new RegExp(path, 'i'); + var route = new RegExp('^' + path, 'i'); self.routes.push({ route: route, @@ -137,7 +137,6 @@ ProxyTable.prototype.getProxyLocation = function (req) { for (var i in this.routes) { var route = this.routes[i]; if (target.match(route.route)) { - var pathSegments = route.path.split('/'); if (pathSegments.length > 1) {