diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-04-05 17:42:26 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 17:42:26 +0530 |
commit | ee4bfe16009c3a04c9015bf9fca0c9b0f9a3a601 (patch) | |
tree | d02cefbebdfc5f876b6f1549ac94d19fb799fb56 | |
parent | f4b11db072c82f1c5e3af6e601faf3626728ab50 (diff) |
fix(ext/node): hostname is valid IPv4 addr (#23243)
Fixes `docusaurus serve`
-rw-r--r-- | ext/node/polyfills/http.ts | 5 | ||||
-rw-r--r-- | tests/unit_node/http_test.ts | 4 |
2 files changed, 7 insertions, 2 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 933a8dbcd..67981e8de 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -1653,7 +1653,10 @@ export class ServerImpl extends EventEmitter { // TODO(bnoordhuis) Node prefers [::] when host is omitted, // we on the other hand default to 0.0.0.0. - const hostname = options.host ?? "0.0.0.0"; + let hostname = options.host ?? "0.0.0.0"; + if (hostname == "localhost") { + hostname = "127.0.0.1"; + } this.#addr = { hostname, port, diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts index 57ade6298..049cdbbbc 100644 --- a/tests/unit_node/http_test.ts +++ b/tests/unit_node/http_test.ts @@ -27,7 +27,9 @@ Deno.test("[node/http listen]", async () => { const { promise, resolve } = Promise.withResolvers<void>(); const server = http.createServer(); - server.listen(() => { + server.listen(42453, "localhost", () => { + // @ts-ignore address() is not a string + assertEquals(server.address()!.address, "127.0.0.1"); server.close(); }); server.on("close", () => { |