Repository navigation
Description
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.
Activity
[-]path regression[/-][+]path regression (trailing slash is added)[/+][-]path regression (trailing slash is added)[/-][+]path regression (trailing slash is added in 0.5.2)[/+]chimurai commentedon May 21, 2026
Fix by revert: 5cb386e
Released in: https://github.com/unjs/httpxy/releases/tag/v0.5.3