1
0
silverbullet/packages/silverbullet-server/server.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-03-27 07:55:29 +00:00
#!/usr/bin/env node
import express from "express";
import http from "http";
import yargs from "yargs";
2022-04-01 15:32:03 +00:00
import { hideBin } from "yargs/helpers";
import { SilverBulletHooks } from "@silverbulletmd/common/manifest";
2022-04-01 15:32:03 +00:00
import { ExpressServer } from "./api_server";
import { System } from "@silverbulletmd/plugos/system";
import path from "path";
let args = yargs(hideBin(process.argv))
2022-04-01 15:32:03 +00:00
.option("port", {
type: "number",
default: 3000,
})
.parse();
2022-03-27 07:55:29 +00:00
if (!args._.length) {
2022-04-01 15:32:03 +00:00
console.error("Usage: silverbullet <path-to-pages>");
process.exit(1);
2022-03-27 07:55:29 +00:00
}
2022-03-21 14:21:34 +00:00
const pagesPath = args._[0] as string;
const app = express();
const server = http.createServer(app);
2022-03-23 14:41:12 +00:00
const system = new System<SilverBulletHooks>("server");
2022-03-21 14:21:34 +00:00
const port = args.port;
const distDir = path.resolve(`${__dirname}/../../silverbullet-web/dist`);
app.use("/", express.static(distDir));
2022-03-21 14:21:34 +00:00
const expressServer = new ExpressServer(app, pagesPath, distDir, system);
expressServer
2022-03-27 09:26:13 +00:00
.init()
.then(async () => {
2022-03-29 10:13:46 +00:00
server.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
2022-03-27 09:26:13 +00:00
})
.catch((e) => {
console.error(e);
});