Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/plugins/default/logger-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,30 @@ export const loggerPlugin: Plugin = (proxyServer, options) => {
const originalUrl = req.originalUrl ?? `${req.baseUrl || ''}${req.url}`;

// construct targetUrl
const port = getPort(proxyRes.req?.agent?.sockets);
let target: URL;

const obj = {
protocol: proxyRes.req.protocol,
host: proxyRes.req.host,
pathname: proxyRes.req.path,
} as URL;
try {
const port = getPort(proxyRes.req?.agent?.sockets);

const target = new URL(`${obj.protocol}//${obj.host}${obj.pathname}`);
const obj = {
protocol: proxyRes.req.protocol,
host: proxyRes.req.host,
pathname: proxyRes.req.path,
} as URL;

if (port) {
target.port = port;
target = new URL(`${obj.protocol}//${obj.host}${obj.pathname}`);

if (port) {
target.port = port;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
// nock issue (https://github.com/chimurai/http-proxy-middleware/issues/1035)
// fallback to old implementation (less correct - without port)
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}]`;
Expand Down