Browse Source

added hostname option to serve command (#519)

* added hostname option to serve command

* update log to include hostname  and port
pull/523/head
Kyle Spearrin 4 years ago committed by GitHub
parent
commit
f8e0e8be06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/commands/serve.command.ts
  2. 12
      src/program.ts

5
src/commands/serve.command.ts

@ -147,6 +147,7 @@ export class ServeCommand { @@ -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 { @@ -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);
});
}

12
src/program.ts

@ -470,12 +470,20 @@ export class Program extends BaseProgram { @@ -470,12 +470,20 @@ export class Program extends BaseProgram {
program
.command("serve")
.description("Start a RESTful API webserver.")
.option("--port <port>", "The port to run your API webserver on. Default port is 8087.")
.option("--hostname <hostname>", "The hostname to bind your API webserver to.")
.option("--port <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) => {

Loading…
Cancel
Save