Merge branch 'main' of github.com:silverbulletmd/silverbullet

pull/159/head
Zef Hemel 2022-12-05 12:17:27 +01:00
commit 3175b3c948
5 changed files with 18 additions and 10 deletions

View File

@ -79,10 +79,11 @@ terminal:
```shell ```shell
silverbullet <pages-path> silverbullet <pages-path>
``` ```
By default, SB will bind to port `3000` on all interfaces. To specify a
By default, SB will bind to port `3000`, to use a different port use the different address or port to listen on, use the `--hostname` and `--port`
`--port` flag. By default SB doesnt offer any sort of authentication, to add options. By default SB doesnt add authentication, to add
basic password authentication, pass the `--user` flag (e.g. `--user pete:1234`). basic password authentication (BasicAuth), pass the `--user` flag (e.g.
`--user pete:1234` for username `pete` and password `1234`).
Once downloaded and booted, SB will print out a URL to open SB in your browser Once downloaded and booted, SB will print out a URL to open SB in your browser
(spoiler alert: by default this will be http://localhost:3000 ). (spoiler alert: by default this will be http://localhost:3000 ).

View File

@ -5,11 +5,12 @@ import { AssetBundle, AssetJson } from "../plugos/asset_bundle/bundle.ts";
export function serveCommand(options: any, folder: string) { export function serveCommand(options: any, folder: string) {
const pagesPath = path.resolve(Deno.cwd(), folder); const pagesPath = path.resolve(Deno.cwd(), folder);
const hostname = options.hostname || "0.0.0.0";
const port = options.port || 3000; const port = options.port || 3000;
console.log( console.log(
"Going to start Silver Bullet on port", "Going to start Silver Bullet on",
port, `${hostname}:${port}`,
"serving pages from", "serving pages from",
pagesPath, pagesPath,
"with db file", "with db file",
@ -17,6 +18,7 @@ export function serveCommand(options: any, folder: string) {
); );
const httpServer = new HttpServer({ const httpServer = new HttpServer({
hostname,
port: port, port: port,
pagesPath: pagesPath, pagesPath: pagesPath,
dbPath: path.join(pagesPath, options.db), dbPath: path.join(pagesPath, options.db),

View File

@ -7,6 +7,7 @@ import { SpaceSystem } from "./space_system.ts";
import { parseYamlSettings } from "../common/util.ts"; import { parseYamlSettings } from "../common/util.ts";
export type ServerOptions = { export type ServerOptions = {
hostname: string;
port: number; port: number;
pagesPath: string; pagesPath: string;
dbPath: string; dbPath: string;
@ -20,12 +21,14 @@ const staticLastModified = new Date().toUTCString();
export class HttpServer { export class HttpServer {
app: Application; app: Application;
systemBoot: SpaceSystem; systemBoot: SpaceSystem;
private hostname: string;
private port: number; private port: number;
user?: string; user?: string;
settings: { [key: string]: any } = {}; settings: { [key: string]: any } = {};
abortController?: AbortController; abortController?: AbortController;
constructor(options: ServerOptions) { constructor(options: ServerOptions) {
this.hostname = options.hostname;
this.port = options.port; this.port = options.port;
this.app = new Application(); //{ serverConstructor: FlashServer }); this.app = new Application(); //{ serverConstructor: FlashServer });
this.user = options.user; this.user = options.user;
@ -129,13 +132,14 @@ export class HttpServer {
}); });
this.abortController = new AbortController(); this.abortController = new AbortController();
this.app.listen({ port: this.port, signal: this.abortController.signal }) this.app.listen({ hostname: this.hostname, port: this.port, signal: this.abortController.signal })
.catch((e: any) => { .catch((e: any) => {
console.log("Server listen error:", e.message); console.log("Server listen error:", e.message);
Deno.exit(1); Deno.exit(1);
}); });
const visibleHostname = this.hostname === "0.0.0.0" ? "localhost" : this.hostname;
console.log( console.log(
`Silver Bullet is now running: http://localhost:${this.port}`, `Silver Bullet is now running: http://${visibleHostname}:${this.port}`,
); );
} }

View File

@ -19,6 +19,7 @@ await new Command()
.usage("<options> <folder> | <command> (see below)") .usage("<options> <folder> | <command> (see below)")
// Main command // Main command
.arguments("<folder:string>") .arguments("<folder:string>")
.option("--hostname <hostname:string>", "Hostname or address to listen on")
.option("-p, --port <port:number>", "Port to listen on") .option("-p, --port <port:number>", "Port to listen on")
.option("--db <dbfile:string>", "Filename for the database", { .option("--db <dbfile:string>", "Filename for the database", {
default: "data.db", default: "data.db",

View File

@ -18,7 +18,7 @@ Lets have a look at some of its features.
* Silver Bullet is [open source, MIT licensed](https://github.com/silverbulletmd/silverbullet) software. * Silver Bullet is [open source, MIT licensed](https://github.com/silverbulletmd/silverbullet) software.
![Screencast screenshot](demo-video-screenshot.png) ![Screencast screenshot](demo-video-screenshot.png)
To get a good feel of what Silver Bullet is capable of, [have a look at at this **introduction video**](https://youtu.be/VemS-cqAD5k). To get a good feel of what Silver Bullet is capable of, [have a look at at this introduction video](https://youtu.be/VemS-cqAD5k).
## Try it ## Try it
Heres the kicker: Heres the kicker:
@ -103,7 +103,7 @@ To run Silver Bullet, create a folder for your pages (it can be empty, or be an
silverbullet <pages-path> silverbullet <pages-path>
``` ```
By default, Silver Bullet will bind to port `3000`, to use a different port use the the `--port` flag. By default Silver Bullet is unauthenticated, to password-protect it, specify a username and password with the `--user` flag (e.g. `--user pete:1234`). By default, Silver Bullet will bind to port `3000`, to use a different port use the the `--port` flag. By default Silver Bullet is unauthenticated, to password-protect it, specify a username and password with the `--user` flag (e.g. `--user pete:mypassword`).
Once downloaded and booted, Silver Bullet will print out a URL to open SB in your browser (by default this will be http://localhost:3000 ). Once downloaded and booted, Silver Bullet will print out a URL to open SB in your browser (by default this will be http://localhost:3000 ).