Skip to content
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

localhost instead of 127.0.0.1 #66

Closed
jeroencusters opened this issue Nov 5, 2015 · 5 comments
Closed

localhost instead of 127.0.0.1 #66

jeroencusters opened this issue Nov 5, 2015 · 5 comments

Comments

@jeroencusters
Copy link

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.

@mattborn
Copy link

👍

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.

@tapio
Copy link
Owner

tapio commented Dec 6, 2015

It was localhost first, but it had problems (see #7). Apparantly there is no one address that works properly everywhere. :(

@mattborn
Copy link

mattborn commented Dec 7, 2015

@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.

@tapio
Copy link
Owner

tapio commented Dec 9, 2015

The code used the resulting IP address of the given host string as the open url. I've now changed it in c94694b to use the user supplied string so that live-server --host=localhost really opens the browser at literally the string "localhost".

@tapio tapio closed this as completed Dec 9, 2015
@mattborn
Copy link

@tapio ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants