-
Notifications
You must be signed in to change notification settings - Fork 852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http-proxy-middleware v3 adds a '/' before query parameters ending up with 404 #1016
Comments
same here |
@chimurai mentioned in #985 (comment) that this is an upstream issue in the (unmaintained) 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 createProxyMiddleware({
target: `https://otherhost/api`,
changeOrigin: true,
pathRewrite: (path) => path.replace(/\/(?:(?=\?)|$)/, ""),
}); I have a feeling this one might not be perfect either though :/ |
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. |
I am more wondering why this does occur with the |
The legacy behaviour is on L30: http-proxy-middleware/src/http-proxy-middleware.ts Lines 124 to 131 in 897611a
To help investigation, it would be helpful to provide a minimal reproduction of the issue. |
I ran into this issue after upgrading from v2 to v3, where an extra / was being added before query parameters. On v2, a configuration like:
would correctly proxy https://myapp.com/xyz.json to https://example.com/xyz.json. After upgrading to v3 and switching to the new API:
the proxied request became https://example.com/xyz.json/, causing a 404 on our end. As a workaround, I’ve explicitly controlled the path using pathRewrite and req.baseUrl:
This ensures that the trailing slash isn’t appended, and matches what the previous v2 version outputted. |
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
The text was updated successfully, but these errors were encountered: