diff --git a/lib/proxy.js b/lib/proxy.js index 1d876c0..168435e 100755 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -292,7 +292,7 @@ ReverseProxy.prototype.setupHttpsProxy = function (proxy, websocketsUpgrade, log var httpsServer = (this.httpsServer = https.createServer(ssl, function (req, res) { var src = _this._getSource(req); - var httpProxyOpts = Object.assign({}, _this.opts.httpProxy); + var httpProxyOpts = Object.assign({secure:false}, _this.opts.httpProxy); _this._getTarget(src, req, res).then(function (target) { if (target) { @@ -681,7 +681,7 @@ ReverseProxy.prototype._getTarget = function (src, req, res) { req.host = target.host; } - if (route.opts.onRequest) { + if (route.opts && route.opts.onRequest) { const resultFromRequestHandler = route.opts.onRequest(req, res, target); if (resultFromRequestHandler !== undefined) { this.log && @@ -761,7 +761,11 @@ function redirectToHttps(req, res, target, ssl, log) { var targetPort = ssl.redirectPort || ssl.port; var hostname = req.headers.host.split(':')[0] + (targetPort ? ':' + targetPort : ''); - var url = 'https://' + path.posix.join(hostname, req.url); + var redirectPath = req.url + if (req.url.indexOf(target.path)===0){ + redirectPath = redirectPath.replace(target.path, "") + } + var url = 'https://' + path.posix.join(hostname, redirectPath); log && log.info('Redirecting %s to %s', path.posix.join(req.headers.host, req.url), url); // // We can use 301 for permanent redirect, but its bad for debugging, we may have it as