Skip to content

Commit

Permalink
fix: prevent open 0.0.0.0 in browser due windows problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Phecda committed Mar 28, 2023
1 parent 8850b18 commit 04e74f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/Server.js
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions test/server/open-option.test.js
Expand Up @@ -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(
Expand All @@ -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,
});
});
Expand Down

0 comments on commit 04e74f2

Please sign in to comment.