-
Notifications
You must be signed in to change notification settings - Fork 65
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
actual fix for issue #43 #46
base: master
Are you sure you want to change the base?
Conversation
…n, I added a new case check for req.url URLs that contain '/?query=param' as well as '?query=param', tests pass
can you add a test to make sure it works? |
Yeah good call. Will get one written up. |
@andrewrk so I spent a couple more hours on this and I have to apologize. The error I was tracking down was due to an improper invocation of your library in a downstream module. It was causing the proxy to append a trailing slash on mounted routes. My initial PR doesn't change the functionality, so you can either leave the code as-is or revert my changes. Sorry again for the confusion. |
Ok, so I think I'm inadvertently trying to set a new record for the amount of times I can stick my foot in my mouth. Here's the next, and hopefully final, double back. I'm about to push up a new code change to slashJoin - this should resolve the issue I was experiencing. I'll do my best to explain what was happening, this is a bit confusing. I was indirectly leveraging proxies: [{ source: '/search', target: 'http://localhost:3001/search' }] which in app.use(config.proxies[i].source, proxy(proxyoptions)); When invoked in this way, without specifying a route via the options.route // without options.route
req.url = /?query=param
// with options.route
req.url = ?query=param The effect of this is, when you have a route without a trailing slash, the path gets removed, but the mount point gets a slash added in by connect. So when the path p1 and p2 get put through path: '/search/?....' On the destination server it is expecting To fix this first part, we need to adjust the way we call into the proxy, by setting the route parameter on the options object in src/index.js instead proxyoptions.route = config.proxies[i].source;
app.use(proxy(proxyoptions)); This will now give us a properly mounted route. The final step is to make sure we don't automatically add an unnecessary slash in via the function slashJoin(p1, p2) {
if (p1.length && p1[p1.length - 1] === '/' && p2.length && p2[0] === '/') {p2 = p2.substring(1); }
return p1 + p2;
} This way, if there is no trailing slash, we don't add one. I was going to write a test up for this, but the test suite already has a test covering this use case. ✓ Can proxy just the given route with query. If this made any sense and you feel comfortable merging my pending changes, I would really appreciate it. I'm going to go bug @hiddentao to alter the invocation of your module and hopefully be on my way to using your two great libraries. TL;DR - slashJoin always adds a slash between p1 and p2, even if there is no trailing slash on the p1 path route, or leading slash on the p2 route. This is incorrect. I fixed this automatic URL rewrite, ensured tests pass, and ensured the overall use case works. |
…ists on either p1 or p2, or on both.
@jlank I've updated |
@hiddentao that is great thank you, I'll test it out now! |
@hiddentao works for me, which is great, thank you. @andrewrk the version at master works for my use case and passes the existing tests so we may be able to ignore this PR, because I think the logic is the same as before. |
reverted slashJoin function, the faulty logic was outside the function, I added a new case check for req.url URLs that contain '/?query=param' as well as '?query=param', tests pass. Closes #43 after merge, bump, and publish.