2022-10-24 11:51:26 +00:00
|
|
|
import { path } from "../server/deps.ts";
|
|
|
|
import { HttpServer } from "../server/http_server.ts";
|
|
|
|
import assetBundle from "../dist/asset_bundle.json" assert { type: "json" };
|
|
|
|
import { AssetBundle, AssetJson } from "../plugos/asset_bundle/bundle.ts";
|
|
|
|
|
|
|
|
export function serveCommand(options: any, folder: string) {
|
|
|
|
const pagesPath = path.resolve(Deno.cwd(), folder);
|
2022-12-16 12:00:06 +00:00
|
|
|
const hostname = options.hostname || "127.0.0.1";
|
2022-10-24 11:51:26 +00:00
|
|
|
const port = options.port || 3000;
|
2023-01-13 14:41:29 +00:00
|
|
|
const bareMode = options.bare;
|
2022-10-24 11:51:26 +00:00
|
|
|
|
|
|
|
console.log(
|
2023-01-16 15:45:55 +00:00
|
|
|
"Going to start SilverBullet binding to",
|
2022-12-04 05:24:06 +00:00
|
|
|
`${hostname}:${port}`,
|
2022-10-24 11:51:26 +00:00
|
|
|
);
|
2022-12-16 12:00:06 +00:00
|
|
|
console.log("Serving pages from", pagesPath);
|
|
|
|
|
|
|
|
if (hostname === "127.0.0.1") {
|
|
|
|
console.log(
|
2023-01-16 15:45:55 +00:00
|
|
|
`_Note:_ SilverBullet will only be available locally (via http://localhost:${port}), to allow outside connections, pass --host 0.0.0.0 as a flag.`,
|
2022-12-16 12:00:06 +00:00
|
|
|
);
|
|
|
|
}
|
2022-10-24 11:51:26 +00:00
|
|
|
|
|
|
|
const httpServer = new HttpServer({
|
2022-12-04 05:24:06 +00:00
|
|
|
hostname,
|
2022-10-24 11:51:26 +00:00
|
|
|
port: port,
|
|
|
|
pagesPath: pagesPath,
|
2022-11-26 13:15:38 +00:00
|
|
|
dbPath: path.join(pagesPath, options.db),
|
2022-10-24 11:51:26 +00:00
|
|
|
assetBundle: new AssetBundle(assetBundle as AssetJson),
|
2022-12-05 11:14:21 +00:00
|
|
|
user: options.user,
|
2023-01-13 14:41:29 +00:00
|
|
|
bareMode,
|
2022-10-24 11:51:26 +00:00
|
|
|
});
|
|
|
|
httpServer.start().catch((e) => {
|
2022-11-25 12:08:59 +00:00
|
|
|
console.error("HTTP Server error", e);
|
|
|
|
Deno.exit(1);
|
2022-10-24 11:51:26 +00:00
|
|
|
});
|
|
|
|
}
|