diff options
author | Luca Casonato <hello@lcas.dev> | 2024-06-09 02:03:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-09 02:03:07 +0200 |
commit | f5d749d922e6434b876ac322ce0c1aeb9af1078c (patch) | |
tree | 8118bf115c4f8310b269140f26e43ee1f14d5058 /ext/http/00_serve.ts | |
parent | ed13d36e4bd9f36e0b8bce6a5e1c25a5b1f5560f (diff) |
fix(ext/http): print `[]` around ipv6 addresses (#24150)
Diffstat (limited to 'ext/http/00_serve.ts')
-rw-r--r-- | ext/http/00_serve.ts | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/http/00_serve.ts b/ext/http/00_serve.ts index 1f83ce73d..7c665ac15 100644 --- a/ext/http/00_serve.ts +++ b/ext/http/00_serve.ts @@ -34,6 +34,7 @@ const { ObjectPrototypeIsPrototypeOf, PromisePrototypeCatch, PromisePrototypeThen, + StringPrototypeIncludes, Symbol, TypeError, TypedArrayPrototypeGetSymbolToStringTag, @@ -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}/`); } }; |