diff --git a/src/commands/serve.command.ts b/src/commands/serve.command.ts index 5f5f72f6b6a..bbea6caaa13 100644 --- a/src/commands/serve.command.ts +++ b/src/commands/serve.command.ts @@ -147,6 +147,7 @@ export class ServeCommand { async run(options: program.OptionValues) { const port = options.port || 8087; + const hostname = options.hostname || "localhost"; const server = new koa(); const router = new koaRouter(); process.env.BW_SERVE = "true"; @@ -355,8 +356,8 @@ export class ServeCommand { server .use(router.routes()) .use(router.allowedMethods()) - .listen(port, () => { - this.main.logService.info("Listening on port " + port); + .listen(port, hostname === "all" ? null : hostname, () => { + this.main.logService.info("Listening on " + hostname + ":" + port); }); } diff --git a/src/program.ts b/src/program.ts index 2c3401dce88..2644bac9d6c 100644 --- a/src/program.ts +++ b/src/program.ts @@ -470,12 +470,20 @@ export class Program extends BaseProgram { program .command("serve") .description("Start a RESTful API webserver.") - .option("--port ", "The port to run your API webserver on. Default port is 8087.") + .option("--hostname ", "The hostname to bind your API webserver to.") + .option("--port ", "The port to run your API webserver on.") .on("--help", () => { - writeLn("\n Examples:"); + writeLn("\n Notes:"); + writeLn(""); + writeLn(" Default hostname is `localhost`."); + writeLn(" Use hostname `all` for no hostname binding."); + writeLn(" Default port is `8087`."); + writeLn(""); + writeLn(" Examples:"); writeLn(""); writeLn(" bw serve"); writeLn(" bw serve --port 8080"); + writeLn(" bw serve --hostname bwapi.mydomain.com --port 80"); writeLn("", true); }) .action(async (cmd) => {