silverbullet/packages/server/server.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-05-04 22:31:11 +08:00
#!/usr/bin/env -S node --enable-source-maps
2022-10-06 21:14:21 +08:00
import * as flags from "https://deno.land/std@0.158.0/flags/mod.ts";
import * as path from "https://deno.land/std@0.158.0/path/mod.ts";
import { ExpressServer } from "./express_server.ts";
2022-04-27 02:31:31 +08:00
2022-10-06 21:14:21 +08:00
type ServerArgs = {
_: string[];
port: number;
password: string;
};
let args: ServerArgs = flags.parse(Deno.args);
2022-03-27 15:55:29 +08:00
if (!args._.length) {
2022-05-04 22:26:52 +08:00
console.error(
2022-10-06 21:14:21 +08:00
"Usage: silverbullet [--port 3000] [--password mysecretpassword] <path-to-pages>",
2022-05-04 22:26:52 +08:00
);
2022-10-06 21:14:21 +08:00
Deno.exit(1);
2022-03-27 15:55:29 +08:00
}
2022-10-06 21:14:21 +08:00
const pagesPath = path.resolve(Deno.cwd(), args._[0] as string);
const port = args.port ? +args.port : 3000;
2022-04-26 01:46:08 +08:00
2022-10-07 22:27:47 +08:00
// const webappDistDir = new URL("./../../dist", import.meta.url).pathname;
// console.log("Webapp dist dir", webappDistDir);
import assetBundle from "../../dist_bundle.json" assert { type: "json" };
2022-10-06 21:14:21 +08:00
const plugDistDir = new URL("./../plugs/dist", import.meta.url).pathname;
console.log("Pages dir", pagesPath);
2022-04-30 00:54:27 +08:00
const expressServer = new ExpressServer({
port: port,
pagesPath: pagesPath,
2022-10-07 22:27:47 +08:00
assetBundle: assetBundle,
2022-04-30 00:54:27 +08:00
builtinPlugDir: plugDistDir,
2022-06-28 20:14:15 +08:00
password: args.password,
2022-04-30 00:54:27 +08:00
});
2022-04-25 00:06:34 +08:00
expressServer.start().catch((e) => {
console.error(e);
});