Repository: http-party/http-server (language: javascript)

Issue:
Open (-o) option now defaults to http://0.0.0.0
**Steps to reproduce the issue, if applicable. Include the actual command and output and/or stack trace.**

Run the following simple command:
`http-server -o some-page.htm`

**What did you expect to happen?**
I expect http-server to open _some-page.htm_ automatically in my browser using a valid local address (http://127.0.0.1/some-page.htm)

**What actually happened?**
My browser opened to an empty page on http://0.0.0.0:8080/some-page.htm

**Tell us about your environment**
- **exact http-server version:**: 13.0.1
- **Node version:**: 14.15.2
- **Platform:**: Win 10

**Other information (related issues, suggestions for a fix, etc):**
This issue just popped up when I updated from v0.12.3 to 13.0.1 and it is caused by issue https://github.com/http-party/http-server/issues/615 and pull https://github.com/http-party/http-server/pull/642. After some research, I realized I can fix it by adding the _address to use_ `-a` to my command line arguments like so...

`http-server -o some-page.htm -a http://127.0.0.1`

But the `-o ` option previously worked without specifying the address.  Shouldn't the server still default to 127.0.1 _if_ no address is specified? As far as I can tell, all that pull request was supposed to do was to allow users to _set_ the address to 0.0.0.0, not make it as the new default. But if this was intentional, perhaps you should note in your documentation that the `-o `option should now be used with the `-a `option.


Discussion / hints:
Replicated on http-server 13.0.0, Node 16.9.0 and Win 10.

Reading the README it is clear that 0.0.0.0 is the default, but much like OP I recommend that 127.0.0.1 is used as the default even if the pull request to allow 0.0.0.0 to be used remains. It is far more intuitive.

I am using `-a 127.0.0.1` without the http:// and everything works fine for both http and https.
Funny, I missed that note in the README, but it looks like that was added to the README 10 years ago in https://github.com/http-party/http-server/commit/8fe1ac870ae5b7cb2c660b74de79184c07bef4ed and it wasn't the default with the `-o` argument until the recent change was made above. 
I'm also experiencing this issue. Here is my npm script:

`http-server public -p 4488 -P http://127.0.0.1:4488? -o`

or

`http-server public -a 0.0.0.0 -p 4488 -P http://127.0.0.1:4488? -o`

Although this allows me to access within my LAN (which is what I want), it opens my webpage locally in http:0.0.0.0 (which I don't want).

If `-a` is set to `0.0.0.0` or omitted, can the address automatically default to `127.0.0.1` so it opens up correctly in the browser while still allowing access to our webpages across the LAN?


I also don't want to set `-a 127.0.0.1` because I can no longer access my webpages across the LAN (even though it will open up correctly in the browser).
I'm unable to reproduce this, but I don't have access to a Windows machine, so it might be Windows-specific, it would appear the OS isn't handling 0.0.0.0 properly and we may need to hold its hand.

When using `-o` and it opens to http://0.0.0.0, if you manually go to http://127.0.0.1 is it running there? Or is it not, which would be a bigger issue?
> I'm unable to reproduce this, but I don't have access to a Windows machine, so it might be Windows-specific

this is most likely a windows-specific issue.

> When using -o and it opens to http://0.0.0.0, if you manually go to http://127.0.0.1 is it running there?

Yes, manually going to http://127.0.0.1 works.

I just tested on my windows machine using the command `http-server public -p 4321 -P http://127.0.0.1:4321? -o` and I get the following output:

```shell
$ yarn serve
yarn run v1.22.11
$ http-server public -p 4321 -P http://127.0.0.1:4321? -o
Starting up http-server, serving public

http-server settings: 
CORS: disabled
Cache: 3600 seconds
Connection Timeout: 120 seconds
Directory Listings: visible
AutoIndex: visible
Serve GZIP Files: false
Serve Brotli Files: false
Default File Extension: none

Available on:
  http://192.168.xxx.1:4321
  http://192.168.1.xxx:4321
  http://127.0.0.1:4321
Unhandled requests will be served from: http://127.0.0.1:4321?
Hit CTRL-C to stop the server
open: http://0.0.0.0:4321
```
It works fine at http://127.0.0.1. But it is tedious to see a "This site can’t be reached" message each time I launch with the `-o` argument, then need to manually navigate to that address.  This is not a huge issue, but I posted it because it previously worked without having to do this and the recent code change I listed above broke it.

I'm also on Windows.

Fix patch:
diff --git a/bin/http-server b/bin/http-server
index fefa6819..1a759085 100755
--- a/bin/http-server
+++ b/bin/http-server
@@ -163,8 +163,7 @@ function listen(port) {
 
   var server = httpServer.createServer(options);
   server.listen(port, host, function () {
-    var canonicalHost = host,
-        protocol      = ssl ? 'https://' : 'http://';
+    var protocol = ssl ? 'https://' : 'http://';
 
     logger.info([colors.yellow('Starting up http-server, serving '),
       colors.cyan(server.root),
@@ -185,9 +184,8 @@ function listen(port) {
     logger.info(colors.yellow('\nAvailable on:'));
 
     if (argv.a && host !== '0.0.0.0') {
-      logger.info(('  ' + protocol + canonicalHost + ':' + colors.green(port.toString())));
-    }
-    else {
+      logger.info(`  ${protocol}${host}:${colors.green(port.toString())}`);
+    } else {
       Object.keys(ifaces).forEach(function (dev) {
         ifaces[dev].forEach(function (details) {
           if (details.family === 'IPv4') {
@@ -203,13 +201,17 @@ function listen(port) {
 
     logger.info('Hit CTRL-C to stop the server');
     if (argv.o) {
-      var openUrl = protocol + canonicalHost + ':' + port;
+      const openHost = host === '0.0.0.0' ? '127.0.0.1' : host;
+      let openUrl = `${protocol}${openHost}:${port}`;
       if (typeof argv.o === 'string') {
         openUrl += argv.o[0] === '/' ? argv.o : '/' + argv.o;
       }
-      logger.info('open: ' + openUrl);
+      logger.info('Open: ' + openUrl);
       opener(openUrl);
     }
+
+    // Spacing before logs
+    if (!argv.s) logger.info();
   });
 }
 


Test patch: