[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.
This commit is contained in:
Maciej Małecki 2011-12-18 21:43:33 +01:00
parent 9f05e6c567
commit 63dfc7f175

View File

@ -97,7 +97,7 @@ ProxyTable.prototype.setRoutes = function (router) {
this.routes = []; this.routes = [];
Object.keys(router).forEach(function (path) { Object.keys(router).forEach(function (path) {
var route = new RegExp(path, 'i'); var route = new RegExp('^' + path, 'i');
self.routes.push({ self.routes.push({
route: route, route: route,
@ -137,7 +137,6 @@ ProxyTable.prototype.getProxyLocation = function (req) {
for (var i in this.routes) { for (var i in this.routes) {
var route = this.routes[i]; var route = this.routes[i];
if (target.match(route.route)) { if (target.match(route.route)) {
var pathSegments = route.path.split('/'); var pathSegments = route.path.split('/');
if (pathSegments.length > 1) { if (pathSegments.length > 1) {