diff --git a/lib/http-proxy/common.ts b/lib/http-proxy/common.ts index 5ae4f62..7a5db0c 100644 --- a/lib/http-proxy/common.ts +++ b/lib/http-proxy/common.ts @@ -112,7 +112,7 @@ export function setupOutgoing( // target if defined is a URL object so has attribute "pathname", not "path". const targetPath = - target && options.prependPath !== false && 'pathname' in target ? getPath(target.pathname) : "/"; + target && options.prependPath !== false && 'pathname' in target ? getPath(`${target.pathname}${target.search ?? ""}`) : "/"; let outgoingPath = options.toProxy ? req.url : getPath(req.url); diff --git a/lib/test/lib/http-proxy-common.test.ts b/lib/test/lib/http-proxy-common.test.ts index 1b91e46..5037ec2 100644 --- a/lib/test/lib/http-proxy-common.test.ts +++ b/lib/test/lib/http-proxy-common.test.ts @@ -292,6 +292,33 @@ describe("#setupOutgoing", () => { expect(outgoing.path).toEqual("/forward/src?f=1&s=1"); }); + it("target path is URL and has query string", () => { + const outgoing: any = {}; + setupOutgoing( + outgoing, + { + target: new URL("http://dummy.org/some-path?a=1&b=2"), + }, + { url: "/src?s=1" }, + ); + + expect(outgoing.path).toEqual("/some-path/src?a=1&b=2&s=1"); + }); + + it("target path is URL and has query string with ignorePath", () => { + const outgoing: any = {}; + setupOutgoing( + outgoing, + { + target: new URL("http://dummy.org/some-path?a=1&b=2"), + ignorePath: true, + }, + { url: "/src?s=1" }, + ); + + expect(outgoing.path).toEqual("/some-path?a=1&b=2"); + }); + // // This is the proper failing test case for the common.join problem //