diff --git a/src/http-proxy-middleware.ts b/src/http-proxy-middleware.ts index 6fe301c0..8d1900ee 100644 --- a/src/http-proxy-middleware.ts +++ b/src/http-proxy-middleware.ts @@ -8,7 +8,7 @@ import { verifyConfig } from './configuration'; import { Debug as debug } from './debug'; import { getPlugins } from './get-plugins'; import { getLogger } from './logger'; -import { matchPathFilter } from './path-filter'; +import { matchPathFilter,getUrlPathName } from './path-filter'; import * as PathRewriter from './path-rewriter'; import * as Router from './router'; import type { Filter, Logger, Options, RequestHandler } from './types'; @@ -175,7 +175,8 @@ export class HttpProxyMiddleware { // rewrite path private applyPathRewrite = async (req: http.IncomingMessage, pathRewriter) => { if (pathRewriter) { - const path = await pathRewriter(req.url, req); + const reqPath = getUrlPathName(req.url); + const path = await pathRewriter(reqPath, req); if (typeof path === 'string') { debug('pathRewrite new path: %s', req.url); diff --git a/src/path-filter.ts b/src/path-filter.ts index b1553a88..fbc34eca 100644 --- a/src/path-filter.ts +++ b/src/path-filter.ts @@ -87,7 +87,7 @@ function matchMultiPath(pathFilterList: string[], uri?: string) { * @param {String} uri from req.url * @return {String} RFC 3986 path */ -function getUrlPathName(uri?: string) { +export function getUrlPathName(uri?: string) { return uri && url.parse(uri).pathname; }