Skip to content

Commit c03a450

Browse files
max-mapperAvianFlu
authored andcommitted
simplify proxytable path segment rewrite logic
1 parent 2061c71 commit c03a450

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,12 @@ ProxyTable.prototype.getProxyLocation = function (req) {
138138
var route = this.routes[i];
139139
if (target.match(route.route)) {
140140

141-
var segments = route.path.split('/');
141+
var pathSegments = route.path.split('/');
142142

143-
if (segments.length > 0) {
144-
var lastSegment = new RegExp("/" + segments[segments.length - 1] + "$");
145-
146-
if(req.url.match(lastSegment)) {
147-
req.url = req.url.replace(lastSegment, '/');
148-
}
143+
if (pathSegments.length > 0) {
144+
// don't include the proxytable path segments in the proxied request url
145+
pathSegments = new RegExp("/" + pathSegments.slice(1).join('/'));
146+
req.url = req.url.replace(pathSegments, '');
149147
}
150148

151149
var location = route.target.split(':'),

0 commit comments

Comments
 (0)