Closed jeroencusters closed 8 years ago
:+1:
This affects how I load fonts and whitelisted domains in my font provider. 127.0.0.1
doesn’t load the fonts. localhost
does. I could change the whitelists for all of my font kits, but it would be much easier if this just worked out-of-the-box without having to manually change 127.0.0.1
to localhost
in the address bar. Otherwise the default open: true
feature gets in the way.
In the live-server/index.js
file, I see these relevant lines:
101 · LiveServer.start = function(options) {
…
103 · var host = options.host || '0.0.0.0';
…
136 · var address = server.address();
137 · var serveHost = address.address === "0.0.0.0" ? "127.0.0.1" : address.address;
138 · var serveURL = 'http://' + serveHost + ':' + address.port;
…
211 · };
Not sure the best way to fix this without a better understanding of why this is constructed this way to begin with, otherwise I would make a PR.
It was localhost
first, but it had problems (see #7). Apparantly there is no one address that works properly everywhere. :(
@tapio I get that different environments (OS and browsers) and use cases (http server, websockets, livereload, etc.) each have their own concerns and limitations so it’s prudent to provide a sane default, but I think this issue suggests an explicit host
value should not be converted back to one of the defaults (either 127.0.0.1
or 0.0.0.0
). It should be considered a bug if setting a host
value doesn’t work either as a command-line argument or in the ~/.live-server.json
.
The code used the resulting IP address of the given host string as the open url. I've now changed it in c94694bd5eb95 to use the user supplied string so that live-server --host=localhost
really opens the browser at literally the string "localhost".
@tapio :heart:
Is it possible to open the browser with localhost instead of 127.0.0.1? I tried 'live-server --host=localhost' but this doesn't work.