Open mnadeem opened 1 month ago
same here
@chimurai mentioned in https://github.com/chimurai/http-proxy-middleware/issues/985#issuecomment-2067656422 that this is an upstream issue in the (unmaintained) http-proxy
library. I only started seeing it after upgrading http-proxy-middleware
from 2.0.6 to 3.0.0 though, which use the same http-proxy
version, so that's a bit odd, but perhaps the issue somehow surfaced with #731 ?
Workaround (first attempt):
createProxyMiddleware({
target: `https://otherhost/api`,
changeOrigin: true,
pathRewrite: (path) => path.replace(/\/$/, ""),
});
That doesn't handle URLs with query strings or hashes though.. Second attempt using lookahead to remove /
's followed by either ?
or end of line:
createProxyMiddleware({
target: `https://otherhost/api`,
changeOrigin: true,
pathRewrite: (path) => path.replace(/\/(?:(?=\?)|$)/, ""),
});
I have a feeling this one might not be perfect either though :/
dupe of https://github.com/chimurai/http-proxy-middleware/issues/1000
Indeed related to change in https://github.com/chimurai/http-proxy-middleware/pull/731
trailing slash issue should (ideally) be fixed in http-proxy
trailing slash issue should (ideally) be fixed in http-proxy
The issue is that http-proxy hasn't been updated in 4 years... But this issue doesn't occur in the legacy version, so are you sure it happens in http-proxy
Please fix this issue, other wise it will impact usage of latest version
Hi @mnadeem. It's an open source project. You are welcome fix it upstream or suggest a fix.
I am more wondering why this does occur with the createProxyMiddleware
, but not the legacyCreateProxyMiddleware
. Trying to investigate this a bit more...
The legacy behaviour is on L30:
To help investigation, it would be helpful to provide a minimal reproduction of the issue.
Checks
http-proxy-middleware
.Describe the bug (be clear and concise)
With the following
if a request is being made
https://myapp.com/api/v1/xyz?param1=value
the proxied request is translating tohttps://example.com/api/v1/xyz/?param1=value
resulting in 404. ( Extra / is being added )This was not the case with v2 and even with v3 legacy mode.
Step-by-step reproduction instructions
Expected behavior (be clear and concise)
No "/" should be added,
How is http-proxy-middleware used in your project?
What http-proxy-middleware configuration are you using?
Additional context (optional)
No response