Http-server: kit-es2016 -> http://localhost//127.0.0.1:8080

Created on 4 May 2016  路  14Comments  路  Source: http-party/http-server

I am currently looking into the Aurelia framework, and when I follow the instructions at http://aurelia.io/docs.html#/aurelia/framework/latest/doc/article/getting-started and do the http-server -o -c-1, my Safari (9.1) opens a new tab on "http://localhost//127.0.0.1:8080", which Safari fails to handle. That URL of course is completely wrong. I have tried it on three different versions of Mac OS X.
I reported the problem to Aurelia, https://github.com/aurelia/framework/issues/410, but they said it seems like an issue with the http-server module rather than Aurelia itself. Therefore I report it here.

Most helpful comment

I don't think it's a different situation. The issue is the same, there's always 'localhost//' before the IP address. I don't think the browser makes a difference here, as the 'open ...' comes from node.

All 14 comments

What's the status of this issue?

Works fine on my OS X 10.11.5 with [email protected].

Having the same issue as described trying an AngularJS app. Node 4 on Mac OS.

Having the same issue as described trying an AngularJS app. Node 4 on Mac OS.

Even with nvm use 4, it works for me.

Reproduced.

Opens http://localhost//127.0.0.1:8080 for me with npm run server that is set to "server": "http-server dist/ -o".

Platform:

OS X 10.11.5 (15F34)
Safari Version 9.1.1 (11601.6.17)

[email protected]

$ node --version
v6.2.0

Reproduced.

Note that you get this bug in a different situation than @jkleiser described.

Opens http://localhost//127.0.0.1:8080 for me with npm run server that is set to "server": "http-server dist/ -o".

Cannot confirm that. OS X 10.11.5, Node 6.2.0, http-server 0.9. I used Firefox however.

I don't think it's a different situation. The issue is the same, there's always 'localhost//' before the IP address. I don't think the browser makes a difference here, as the 'open ...' comes from node.

@PatrickHeneise The difference is that @ain passed a directory, while @jkleiser didn't.

Nevertheless, this issue seems to be hard to reproduce.

@derhuerst if it's of any help: not passing a directory isn't resolving the issue, just tested.

I've been using http-server on Windows and Ubuntu Linux without any problems, but I am now facing this issue on Mac. My npm script is the following:

"http": "http-server \"app\" -p 8080 -o"

When I run npm run http on Mac, I get an error on Safari: Safari can't open the page "localhost//127.0.0.1:8080" because Safari can't connect to the server "localhost".

I have to manually enter localhost:8080 or 127.0.0.1:8080 in order for http-server to run without an error.

What could be the issue?

This has nothing to do with Aurelia or AngularJS as previous posters have. I'm just trying to create a simple static html page and run it with http-server.

Also, I used lite-server and I don't get this issue on Mac, Windows and Ubuntu Linux.

For anyone else having this issue, just install lite-server as an npm dependency ("lite": "lite-server") and run npm run lite. You won't have to deal with this issue on Mac

I found the cause. protocol already contains //, so there will be two // in the opener() call.

diff --git a/bin/http-server b/bin/http-server
index 51b0602..5e3e99a 100755
--- a/bin/http-server
+++ b/bin/http-server
@@ -149,7 +149,7 @@ function listen(port) {
     logger.info('Hit CTRL-C to stop the server');
     if (argv.o) {
       opener(
-        protocol + '//' + canonicalHost + ':' + port,
+        protocol + canonicalHost + ':' + port,
         { command: argv.o !== true ? argv.o : null }
       );
     }

Will submit a PR.

@derhuerst - I'm not sure if removing '//' will fix the issue. It seems to me that on Windows and Linux, protocol resolves to http:, but on Mac protocol resolves to http://localhost. Also, canonicalHost resolves to 127.0.0.1 on all three OSes.

This is why the url resolves to http://localhost//127.0.0.1:8080 on Mac (causing an error) and http://127.0.0.1:8080 on Windows and Linux (which works fine).

I think your change will resolve to http://localhost127.0.0.1:8080 on Mac and http:127.0.0.1:8080 on Windows and Linux, which will cause an error on all three OSes.

I think there should be a check on protocol to see if it resolves to http://localhost (as it does on Mac) and, if so, replace it with http: by removing //localhost.

I haven't tested your solution to the problem, so please correct me if I'm wrong.

Thanks for pointing that out!

I think there should be a check on protocol to see if it resolves to http://localhost (as it does on Mac) and, if so, replace it with http: by removing //localhost.

Shouldn't this get fixed upstream?

This should be fixed in the latest version of http-server (I can't reproduce anymore). Please reopen if it shows up again.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dKab picture dKab  路  7Comments

EvgeniGordeev picture EvgeniGordeev  路  4Comments

ghost picture ghost  路  4Comments

gswebspace picture gswebspace  路  6Comments

laughinghan picture laughinghan  路  5Comments