refactor: fix ipv6

This commit is contained in:
Catriel Müller
2026-06-19 11:02:32 -03:00
parent d9bb823c7a
commit 02bbf661b0
2 changed files with 8 additions and 4 deletions
@@ -27,9 +27,8 @@ function format(hostname: string, port: number) {
export function serverUrls(hostname: string, port: number) {
const bind = format(hostname, port)
const wildcard = hostname === "0.0.0.0" || hostname === "::"
const local = wildcard ? format("localhost", port) : bind
const ip = wildcard ? getNetworkIPs()[0] : undefined
const local = hostname === "0.0.0.0" ? format("localhost", port) : hostname === "::" ? format("::1", port) : bind
const ip = hostname === "0.0.0.0" ? getNetworkIPs()[0] : undefined
return {
local,
@@ -52,12 +52,17 @@ describe("server URL display", () => {
})
})
test("formats IPv6 bind URLs", () => {
test("formats IPv6 bind URLs without advertising IPv4 interfaces", () => {
expect(serverUrls("::1", 4096)).toStrictEqual({
local: "http://[::1]:4096",
network: undefined,
bind: "http://[::1]:4096",
})
expect(serverUrls("::", 4096)).toStrictEqual({
local: "http://[::1]:4096",
network: undefined,
bind: "http://[::]:4096",
})
})
})