Skip to content

Commit 63dfc7f

Browse files
committed
[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.
1 parent 9f05e6c commit 63dfc7f

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

lib/node-http-proxy/proxy-table.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ ProxyTable.prototype.setRoutes = function (router) {
9797
this.routes = [];
9898

9999
Object.keys(router).forEach(function (path) {
100-
var route = new RegExp(path, 'i');
100+
var route = new RegExp('^' + path, 'i');
101101

102102
self.routes.push({
103103
route: route,
@@ -137,7 +137,6 @@ ProxyTable.prototype.getProxyLocation = function (req) {
137137
for (var i in this.routes) {
138138
var route = this.routes[i];
139139
if (target.match(route.route)) {
140-
141140
var pathSegments = route.path.split('/');
142141

143142
if (pathSegments.length > 1) {

0 commit comments

Comments
 (0)