Skip to content

Commit

Permalink
fix(ext/http): print [] around ipv6 addresses (denoland#24150)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Jun 9, 2024
1 parent ed13d36 commit f5d749d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ext/http/00_serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const {
ObjectPrototypeIsPrototypeOf,
PromisePrototypeCatch,
PromisePrototypeThen,
StringPrototypeIncludes,
Symbol,
TypeError,
TypedArrayPrototypeGetSymbolToStringTag,
Expand Down Expand Up @@ -656,14 +657,19 @@ function serve(arg1, arg2) {
// If the hostname is "0.0.0.0", we display "localhost" in console
// because browsers in Windows don't resolve "0.0.0.0".
// See the discussion in https://github.com/denoland/deno_std/issues/1165
const hostname = addr.hostname == "0.0.0.0" ? "localhost" : addr.hostname;
const hostname = addr.hostname == "0.0.0.0" || addr.hostname == "::"
? "localhost"
: addr.hostname;
addr.hostname = hostname;

const onListen = (scheme) => {
if (options.onListen) {
options.onListen(addr);
} else {
console.log(`Listening on ${scheme}${addr.hostname}:${addr.port}/`);
const host = StringPrototypeIncludes(addr.hostname, ":")
? `[${addr.hostname}]`
: addr.hostname;
console.log(`Listening on ${scheme}${host}:${addr.port}/`);
}
};

Expand Down

0 comments on commit f5d749d

Please sign in to comment.