mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Fix problem with req.url not being not properly replaced.
This commit is contained in:
parent
a088efdb04
commit
f1611ec8dc
@ -26,7 +26,8 @@
|
|||||||
|
|
||||||
var util = require('util'),
|
var util = require('util'),
|
||||||
events = require('events'),
|
events = require('events'),
|
||||||
fs = require('fs');
|
fs = require('fs'),
|
||||||
|
url = require('url');
|
||||||
|
|
||||||
//
|
//
|
||||||
// ### function ProxyTable (router, silent)
|
// ### function ProxyTable (router, silent)
|
||||||
@ -137,17 +138,17 @@ 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 requrl = url.parse(req.url);
|
||||||
|
//add the 'http://'' to get around a url.parse bug, it won't actually be used.
|
||||||
|
var targeturl = url.parse('http://'+route.target);
|
||||||
|
var pathurl = url.parse('http://'+route.path);
|
||||||
|
|
||||||
if (pathSegments.length > 1) {
|
//This replaces the path's part of the URL to the target's part of the URL.
|
||||||
// don't include the proxytable path segments in the proxied request url
|
requrl.pathname = requrl.pathname.replace(pathurl.pathname, targeturl.pathname);
|
||||||
pathSegments = new RegExp("/" + pathSegments.slice(1).join('/'));
|
req.url = url.format(requrl);
|
||||||
req.url = req.url.replace(pathSegments, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
var location = route.target.split(':'),
|
var host = targeturl.hostname,
|
||||||
host = location[0],
|
port = targeturl.port || 80;
|
||||||
port = location.length === 1 ? 80 : location[1];
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
port: port,
|
port: port,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user