1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Server: correctly print URL when running on IPv6

Since https://github.com/nodejs/node/issues/40537 users are more likely to encounter IPv6 connections.

IPv6 URLs require square brackets around raw addresses.

With this change VS Code correctly hyperlinks the message `Serving on http://[::1]:8080`
This commit is contained in:
jeremy@jermolene.com 2022-07-29 10:07:59 +01:00
parent a453121e96
commit 34b1b8128f

View File

@ -359,8 +359,9 @@ Server.prototype.listen = function(port,host,prefix) {
}
// Display the port number after we've started listening (the port number might have been specified as zero, in which case we will get an assigned port)
server.on("listening",function() {
var address = server.address();
$tw.utils.log("Serving on " + self.protocol + "://" + address.address + ":" + address.port + prefix,"brown/orange");
var address = server.address(),
url = self.protocol + "://" + (address.family === "IPv6" ? "[" + address.address + "]" : address.address) + ":" + address.port + prefix;
$tw.utils.log("Serving on " + url,"brown/orange");
$tw.utils.log("(press ctrl-C to exit)","red");
});
// Listen