diff --git a/lib/http_proxy.js b/lib/http_proxy.js index 49b4838..45b71fb 100644 --- a/lib/http_proxy.js +++ b/lib/http_proxy.js @@ -1,6 +1,7 @@ 'use strict'; -const { URL } = require('url'); +const url = require('url'); +const { URL } = url; const FormStream = require('formstream'); const ContentType = require('content-type'); const address = require('address'); @@ -41,9 +42,10 @@ class HttpProxy { }; if (options.withCredentials === undefined) options.withCredentials = this.config.withCredentials; - - let urlObj = new URL(ctx.href); - urlObj.host = host; + let urlParsed = url.parse(ctx.href); + let index = ctx.href.indexOf(urlParsed.host); + const href = `${host}/${ctx.href.slice(index+1+urlParsed.host.length)}`; + let urlObj = new URL(href); if (options.rewrite) { urlObj = options.rewrite(urlObj); diff --git a/package.json b/package.json index 30bddf6..7954ce0 100644 --- a/package.json +++ b/package.json @@ -60,4 +60,4 @@ "homepage": "https://github.com/eggjs/egg-http-proxy#readme", "author": "TZ ", "license": "MIT" -} +} \ No newline at end of file