Skip to content

path regression (trailing slash is added in 0.5.2) #138

Closed

Description

@chimurai

Environment

Hi,

Tried to update to 0.5.2 in http-proxy-middleware

Looks like #137 introduced regression in paths?

In this specific test /api is not preserved and is now being proxied differently:
https://github.com/chimurai/http-proxy-middleware/pull/1234/changes#diff-89634a91bb39f03a55c0c5ffa685aa8bc2c807017ae554f83caa4cd25cf50a95R160

The url is now send as /api/ to target server. (with trailing slash)

Reproduction

const app = express()

app.use('/', createProxyMiddleware({
    changeOrigin: true,
    target: `http://localhost:9000/api`,        // <--- configure target with path
}));

app.listen(3000)

before: (0.5.1)
curl http://localhost:3000 -> http://localhost:9000/api

after: (0.5.2)
curl http://localhost:3000 -> http://localhost:9000/api/

                                                       ^ Notice the trailing slash

Describe the bug

Trailing slash is added when target is used with path


If I revert the logic from (#137) to the previous, the trailing slash is gone.

function joinURL(base, path) {
	if (!base || base === "/") return path || "/";
  if (!path || path === "/") {     // <---- original
    return base || "/";            // <---- original
  }

  //...
}

Additional context

Recently migrated to httpxy in https://www.npmjs.com/package/http-proxy-middleware

The { target: 'http://[::1]:9000/api' } is quite common pattern to rewrite paths when the proxy is mounted on same or different path in the server.

Logs

Activity

  1. added
    bug
    on May 19, 2026
  2. changed the title [-]path regression[/-] [+]path regression (trailing slash is added)[/+] on May 19, 2026
  3. changed the title [-]path regression (trailing slash is added)[/-] [+]path regression (trailing slash is added in 0.5.2)[/+] on May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions