Skip to content

Commit aa7c88e

Browse files
1j01indexzero
authored andcommitted
Use 127.0.0.1 when listening on 0.0.0.0
1 parent 10f686a commit aa7c88e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

bin/http-server

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ function listen(port) {
8787

8888
var server = httpServer.createServer(options);
8989
server.listen(port, host, function() {
90-
var uri = [ssl ? 'https' : 'http', '://', host, ':', port].join('');
90+
var protocol = ssl ? 'https:' : 'http:';
91+
var canonical_host = host === "0.0.0.0" ? "127.0.0.1" : host;
92+
var uri = protocol + '//' + host + ':' + port;
93+
var canonical_uri = protocol + '//' + canonical_host + ':' + port;
9194
log('Starting up http-server, serving '.yellow
9295
+ server.root.cyan
93-
+ ((ssl) ? ' through'.yellow + ' https'.cyan : '')
96+
+ (ssl ? ' through'.yellow + ' https'.cyan : '')
9497
+ ' on: '.yellow
9598
+ uri.cyan);
9699

@@ -100,7 +103,7 @@ function listen(port) {
100103

101104
log('Hit CTRL-C to stop the server');
102105
if (argv.o) {
103-
opener(uri);
106+
opener(canonical_uri);
104107
}
105108
});
106109
}

0 commit comments

Comments
 (0)