Skip to content

Commit

Permalink
fix: invalid ipv6 hostname on deno serve
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Sep 6, 2024
1 parent ef50a64 commit 292d256
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions ext/http/00_serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,7 @@ function serve(arg1, arg2) {
if (options.onListen) {
options.onListen(addr);
} else {
const host = StringPrototypeIncludes(addr.hostname, ":")
? `[${addr.hostname}]`
: addr.hostname;
const host = formatHostName(addr.hostname);
// deno-lint-ignore no-console
console.log(`Listening on ${scheme}${host}:${addr.port}/`);
}
Expand All @@ -696,6 +694,15 @@ function serve(arg1, arg2) {
return serveHttpOnListener(listener, signal, handler, onError, onListen);
}

/**
* @param {string} received
* @returns {string}
*/
function formatHostName(received) {
// Add brackets around ipv6 host
return StringPrototypeIncludes(received, ":") ? `[${received}]` : received;
}

/**
* Serve HTTP/1.1 and/or HTTP/2 on an arbitrary listener.
*/
Expand Down Expand Up @@ -862,9 +869,11 @@ function registerDeclarativeServer(exports) {
const nThreads = serveWorkerCount > 1
? ` with ${serveWorkerCount} threads`
: "";

const host = formatHostName(hostname);
// deno-lint-ignore no-console
console.debug(
`%cdeno serve%c: Listening on %chttp://${hostname}:${port}/%c${nThreads}`,
`%cdeno serve%c: Listening on %chttp://${host}:${port}/%c${nThreads}`,
"color: green",
"color: inherit",
"color: yellow",
Expand Down

0 comments on commit 292d256

Please sign in to comment.