Skip to content

Exception thrown in logger when trying to build URL for message #1056

@VadBary

Description

@VadBary

Checks

Describe the bug (be clear and concise)

In fact, the solution for the issue has already been implemented for v3.0.2 But implemented fix doesn't work in case when target option is not set but router option is used instead.

Step-by-step reproduction instructions

1. Send a message to an Express route which then uses `http-proxy-middleware` to send a message on to another endpoint
Have an endpoint which sends a response where the `req` object doesn't include all the properties such as `protocol`. I believe mocking framework like `nock` would do this.
2. Use router option instead of target option.

Expected behavior (be clear and concise)

The logger can cope with bits of req not being present when trying to build a valid URL when router option is used instead of target.

How is http-proxy-middleware used in your project?

We are using `http-proxy-middleware `^3.0.3`with express router for routing.

What http-proxy-middleware configuration are you using?

createProxyMiddleware({
     router: (request) => this.route(request),
     agent,
     secure: false,
     changeOrigin: true,
     followRedirects: true,
     ignorePath: true,
     headers: { Connection: 'keep-alive' },
     plugins: [proxyRequestLoggerPlugin],
     on: {
       error: (err, req, res, target) => this.proxyError(err, req, res, target),
       proxyReq: (proxyReq, req) => {
         this.proxyReq(proxyReq, req);
       },
       proxyRes: (proxyRes, req) => {
         this.proxyRes(proxyRes, req);
       },
     },
   });

What OS/version and node/version are you seeing the problem?

Node v20.15.1

Additional context (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions