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
Allow Open -o with both relative & absolute paths #260
Conversation
I'm not sure if @indexzero is interested in this, but squashing your commits would help your case :) Also, this looks like a duplicate of #234 which was opened a few months before this PR. I would recommend closing this and code reviewing #234 if you think this PR has something that was missed. |
I know about #234 but he introduced a breaking change, my pull request does something similar but is a none breaking change to existing peoples code. (Not criticising their code) In their solution everybody would be forced to change any existing code that works with the current implementation to switch from absolute to relative paths. I have given an alternative that introduces relative paths but retains absolute paths. This can be an issue where people have hard coded the absolute path in say an npm script. Hence why the additional pull request. As for the squashing commits, I was not aware you could do that after submitting, it failed only on code style guidance, the same as hancharou did. If it is possible then I am happy to do it, or do you mean before I re-commited the style changes in the first place? I have done years of private company source control work before, but this is in fact my first open source pull request, so I am open to suggestions. |
Cool, thanks for articulating the difference! You can check out https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History for squashing. In your case |
Thank you for the link, I cant do it this minute Ill read through that particular help page properly before I do it, your example makes sense, but will want to make sure I dont do something stupid (the git help pages are great but wow its easy to miss alot when you dont know exactly what your looking for). Thank you again :) |
Lski, My #234 serves all commands correctly and serves all of them through HTTP. This change will open files properly not matter you provide it with |
Sorry but I disagree, I would suggest "index.html" is still a relative path, "http://127.0.0.1:8081/index.html" is an absolute path and what people are probably currently using. Your pull request does not allow absolute paths to be loaded any more which could BREAK their existing build scripts. Although just my opinion I would say starting with a forward "/" slash makes sense with regards to the web as its a root relative from the website you have just started. I am happy to switch my code to sniff for http/https if no slash is really that important and what people want, Im flexible :) or if not, please update your PR so that it doesnt break peoples existing code. |
lski, What do you mean by relative path? You still will be opening root + whatever you have in - |
Ok lets step back from 'relative' and 'absolute' path as it s not so important and focus on the fact your proposing a breaking change. Imagine the following snippet from someones existing packge.json: {
"scripts": {
"build": "http-server -p 8081 -o http://myComputerName/subfolder/index.htm"
}
} In that example it would turn out "http://127.0.0.1/http://myComputerName/subfolder/index.htm" which obviously wont work. You are also making the assumption that people will always want to use "http://127.0.0.1/subfolder/index.html" so will be happy with "http://127.0.0.1/" + whatever they put, but sometimes that just is not what people need to load. The example above of "computer name" host instead of 127.0.0.1 could be because they are using cors with a base api service and need to ensure they are coming from a particular host. Hopefully that makes more sense :) |
Correction "http://myComputerName:8081/subfolder/index.htm" as I missed the port number (sorry on mobile this week). And I meant to mention a local network address IP e.g. "http://192.168.0.1:8081/subfolder/index.htm" |
Why do you keep this line |
Well the check in the original is there because if you pass "non-string" values to the opener via the arguments e.g. true, 2 etc it throws an error, so the check needs to be there. And a check still needs to be made after checking the initial check for the "/", because if it is a string value e.g. a full url "http://127.0.0.1:8080/" it still needs to be passed to behave the same as it did before this change. I believe the author originally passed the command separately as if options.command == null then it will use the first argument, otherwise uses the options.command. I decided to stick with the authors original way as to make it more likely they would be happy with the pull request. Although I should have changed it to the following to avoid other values other than just 'true': opener(typeof argv.o === 'string' ? argv.o : protocol + '//' + canonicalHost + ':' + port); When doing the code I originally wrote something along the lines of the code below: if (argv.o) {
var isStr = (typeof argv.o === 'string');
if (isStr && argv.o.charAt(0) === '/') {
opener(protocol + '//' + canonicalHost + ':' + port + argv.o);
}
else {
opener(isStr ? argv.o : protocol + '//' + canonicalHost + ':' + port);
}
} But I felt I then possibly altering the behaviour of the code, so I put the original line back in. I personally would have preferred to use the my original code as it was easier to read for me and did a check for string values. |
Closes http-party#231 Addresses PRs http-party#234, http-party#250, and http-party#260
any update on this issue? |
any updates on this? Its been a while :) close it or merge it? 😆 |
@andrevenancio I'm not at all opposed to merging this (or one of the similar duplicate attempts at solving it), but (as you've noted) it's been a while, so this (and/or the other approaches) need review/comparison/tests/etc. If you want to help dig through the other related opener issues and make a recommendation (and ideally tests!), then I'm more than happy to review it and (if all is well) merge it. |
@lski do you have time to add a test since you're more into this issue originally? Also, would this make everybody happy:
so things like: will work making everybody happy? 😁 |
@andrevenancio I am currently travelling without a laptop, so not able to atm, sorry |
I believe this should be achieved by the earlier #250. Please comment and/or reopen if this is not the case. |
Allows the use of both absolute and relative paths when using the open flag [-o]. This is a none breaking change as currently the Open option just doesnt work (in my tests) if starting with a forward slash.
Allowing absolute paths is important as someone might want to force the use of a particular host that doesnt want to use the value in canonicalHost.
It determines whether it is a relative path or not simply by checking whether the -o argument starts with a forward slash, anything else passes through as before.