diff --git a/src/plugins/default/logger-plugin.ts b/src/plugins/default/logger-plugin.ts index 00c70bae..b728b05d 100644 --- a/src/plugins/default/logger-plugin.ts +++ b/src/plugins/default/logger-plugin.ts @@ -26,7 +26,13 @@ export const loggerPlugin: Plugin = (proxyServer, options) => { // BrowserSync uses req.originalUrl // Next.js doesn't have req.baseUrl const originalUrl = req.originalUrl ?? `${req.baseUrl || ''}${req.url}`; - const exchange = `[HPM] ${req.method} ${originalUrl} -> ${proxyRes.req.protocol}//${proxyRes.req.host}${proxyRes.req.path} [${proxyRes.statusCode}]`; + + // construct targetUrl + const target = new URL(options.target as URL); + target.pathname = proxyRes.req.path; + const targetUrl = target.toString(); + + const exchange = `[HPM] ${req.method} ${originalUrl} -> ${targetUrl} [${proxyRes.statusCode}]`; logger.info(exchange); }); diff --git a/test/e2e/http-proxy-middleware.spec.ts b/test/e2e/http-proxy-middleware.spec.ts index db6ddb3a..96f2cd80 100644 --- a/test/e2e/http-proxy-middleware.spec.ts +++ b/test/e2e/http-proxy-middleware.spec.ts @@ -459,7 +459,9 @@ describe('E2E http-proxy-middleware', () => { expect(logMessages).not.toBeUndefined(); expect(logMessages.length).toBe(1); - expect(logMessages[0]).toBe('[HPM] GET /api/foo/bar -> http://localhost/api/foo/bar [200]'); + expect(logMessages.at(0)).toBe( + `[HPM] GET /api/foo/bar -> http://localhost:${mockTargetServer.port}/api/foo/bar [200]`, + ); }); }); });