-
Notifications
You must be signed in to change notification settings - Fork 981
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
Support URLs that have a path component #843
Conversation
Fixed erroneous path generation like below: url[http://localhost:3000/something] + get[/foo] -> (should be) http://localhost:3000/something/foo -x->(should not be) http://localhost:3000/foo
if (opts.path && this.url.path && | ||
opts.path !== '/' && this.url.path !== '/') { | ||
// clean up the url path, stripping the last / | ||
opts.path = utils.sanitizePath([this.url.path, opts.path].join('/')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on #692, I think it's safe to say that we probably don't want to strip trailing slashes. Make the users be explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, could probably use url.resolve()
in favor of [].join('/')
;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wouldn't affect #692 as this is a http client making requests to any other http server / endpoint, not the server managing routes.
url.resolve()
won't work if the request url has a / at the beginning, it will replace whatever path is already at the beginning of the path.
url.resolve('/foo/bar', '/baz') === '/baz';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a bummer, maybe we should look into something like URIjs, there's a lot of URL mugging that should be centralized (plugins too).
Re: above sorry, I should have been clearer, I just think that we should be consistent, presumably if users need strict URLs on the server, them they need a client that can hit those strict URLs. If we strip trailing slashes automatically them it's impossible to do so. Maybe we can do a strict:true option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we should definitely standardize the management of urls via the server and client libraries.
Combine both PRs #633 and #628
Pull the logic from #633 and clean it up a bit
Pull the tests from #628
Thanks to both @nakosung and @calebbrown for their contributions.
The goal of this PR is to use the path from both the Client options and the requested url.
For example, when a user creates a client for a non-root url, any subsequent requests should use that as part of the request path.
The resulting request should go to
http://127.0.0.1/str/foo
.