Add --host option npx gulp server

Using `0.0.0.0` instead of `localhost` allows connecting from other
devices, significantly simplifying testing on mobile devices.

This is controlled by the `--host` CLI flag and not enabled by
default, since allowing external connections comes with security
implications (e.g. when on a public network without a properly
configured firewall).

There might be reasons to want to listen on custom hostnames, but as
the most common usage will probably be `--host 0.0.0.0`, there is a
shorter alias `--host 0` for it.
This commit is contained in:
Nicolò Ribaudo 2026-02-10 11:39:01 +01:00
parent 3eca60735b
commit 384f1af067
No known key found for this signature in database
GPG Key ID: AAFDA9101C58F338

View File

@ -2210,8 +2210,17 @@ gulp.task(
}
}
let host;
const j = process.argv.indexOf("--host");
if (j >= 0 && j + 1 < process.argv.length) {
host = process.argv[j + 1];
if (host === "0") {
host = "0.0.0.0";
}
}
const { WebServer } = await import("./test/webserver.mjs");
const server = new WebServer({ port });
const server = new WebServer({ host, port });
server.start();
}
)