diff --git a/lib/Server.js b/lib/Server.js index 573707d640..7dfac5e169 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -2893,7 +2893,11 @@ class Server { } if (/** @type {NormalizedOpen[]} */ (this.options.open).length > 0) { - const openTarget = prettyPrintURL(this.options.host || "localhost"); + const openTarget = prettyPrintURL( + !this.options.host || this.options.host === "0.0.0.0" + ? "localhost" + : this.options.host + ); this.openBrowser(openTarget); } diff --git a/test/server/open-option.test.js b/test/server/open-option.test.js index 23e1cb1526..5a624b00bb 100644 --- a/test/server/open-option.test.js +++ b/test/server/open-option.test.js @@ -99,7 +99,7 @@ describe('"open" option', () => { }); }); - it("should work with '0.0.0.0' host", async () => { + it("should work with '0.0.0.0' host but open localhost", async () => { const host = "0.0.0.0"; const server = new Server( @@ -114,7 +114,7 @@ describe('"open" option', () => { await server.start(); await server.stop(); - expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, { + expect(open).toHaveBeenCalledWith(`http://localhost:${port}/`, { wait: false, }); });