Skip to content

Commit 04e74f2

Browse files
authored
fix: prevent open 0.0.0.0 in browser due windows problems
1 parent 8850b18 commit 04e74f2

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/Server.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -2893,7 +2893,11 @@ class Server {
28932893
}
28942894

28952895
if (/** @type {NormalizedOpen[]} */ (this.options.open).length > 0) {
2896-
const openTarget = prettyPrintURL(this.options.host || "localhost");
2896+
const openTarget = prettyPrintURL(
2897+
!this.options.host || this.options.host === "0.0.0.0"
2898+
? "localhost"
2899+
: this.options.host
2900+
);
28972901

28982902
this.openBrowser(openTarget);
28992903
}

test/server/open-option.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('"open" option', () => {
9999
});
100100
});
101101

102-
it("should work with '0.0.0.0' host", async () => {
102+
it("should work with '0.0.0.0' host but open localhost", async () => {
103103
const host = "0.0.0.0";
104104

105105
const server = new Server(
@@ -114,7 +114,7 @@ describe('"open" option', () => {
114114
await server.start();
115115
await server.stop();
116116

117-
expect(open).toHaveBeenCalledWith(`http://${host}:${port}/`, {
117+
expect(open).toHaveBeenCalledWith(`http://localhost:${port}/`, {
118118
wait: false,
119119
});
120120
});

0 commit comments

Comments
 (0)