From 863b92df6a87ab9221d5d6f64f8b34dd0ac6e6ea Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 24 May 2023 05:42:02 +0200 Subject: [PATCH] Allow configuring the port and folder to be configured with env variables --- cmd/server.ts | 20 +++++++++++++++++--- silverbullet.ts | 2 +- website/Install.md | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/cmd/server.ts b/cmd/server.ts index 19be7f52..95294873 100644 --- a/cmd/server.ts +++ b/cmd/server.ts @@ -12,11 +12,25 @@ import { DiskSpacePrimitives } from "../common/spaces/disk_space_primitives.ts"; import { SpacePrimitives } from "../common/spaces/space_primitives.ts"; import { S3SpacePrimitives } from "../server/spaces/s3_space_primitives.ts"; -export function serveCommand(options: any, folder: string) { +export function serveCommand( + options: any, + folder?: string, +) { const hostname = options.hostname || "127.0.0.1"; - const port = options.port || 3000; + const port = options.port || + (Deno.env.get("SB_PORT") && +Deno.env.get("SB_PORT")!) || 3000; const maxFileSizeMB = options.maxFileSizeMB || 20; + if (!folder) { + folder = Deno.env.get("SB_FOLDER"); + if (!folder) { + console.error( + "No folder specified. Please pass a folder as an argument or set SB_FOLDER environment variable.", + ); + Deno.exit(1); + } + } + console.log( "Going to start SilverBullet binding to", `${hostname}:${port}`, @@ -56,7 +70,7 @@ To allow outside connections, pass -L 0.0.0.0 as a flag, and put a TLS terminato port: port, pagesPath: folder, clientAssetBundle: new AssetBundle(clientAssetBundle as AssetJson), - user: options.user, + user: options.user ?? Deno.env.get("SB_USER"), keyFile: options.key, certFile: options.cert, maxFileSizeMB: +maxFileSizeMB, diff --git a/silverbullet.ts b/silverbullet.ts index f8009cbe..3a785bf9 100755 --- a/silverbullet.ts +++ b/silverbullet.ts @@ -17,7 +17,7 @@ await new Command() }) .usage(" | (see below)") // Main command - .arguments("") + .arguments("[folder:string]") .option( "--hostname, -L ", "Hostname or address to listen on", diff --git a/website/Install.md b/website/Install.md index 7a9d1896..5d0f1375 100644 --- a/website/Install.md +++ b/website/Install.md @@ -19,7 +19,7 @@ This consists of two steps (unless Deno is already installed — in which case w With Deno installed, run: ```shell -deno install -f --name silverbullet -A https://silverbullet.md/silverbullet.js +deno install -f --name silverbullet -A https://get.silverbullet.md ``` This will install `silverbullet` into your `~/.deno/bin` folder (which should already be in your `$PATH` if you followed the Deno install instructions).