From 4b67ffe11b793040c981da5797d1d4f68ef521d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jhan=20S=2E=20=C3=81lvarez?= <51450231+yastanotheruser@users.noreply.github.com> Date: Wed, 14 Jun 2023 07:58:41 -0500 Subject: [PATCH] fix(ext/http): Include hostname in onListen argument (#19497) Closes #19470. --- ext/http/00_serve.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ext/http/00_serve.js b/ext/http/00_serve.js index be9c9d801e..761c3219eb 100644 --- a/ext/http/00_serve.js +++ b/ext/http/00_serve.js @@ -635,16 +635,17 @@ function serve(arg1, arg2) { } const onListen = (scheme) => { + // 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 = listenOpts.hostname == "0.0.0.0" + ? "localhost" + : listenOpts.hostname; const port = listenOpts.port; + if (options.onListen) { - options.onListen({ port }); + options.onListen({ hostname, port }); } else { - // 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 = listenOpts.hostname == "0.0.0.0" - ? "localhost" - : listenOpts.hostname; console.log(`Listening on ${scheme}${hostname}:${port}/`); } };