-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuitsu.js
49 lines (34 loc) · 1.07 KB
/
buitsu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import dotenv from "dotenv";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import yaml from "yaml";
//! project specific
import buitsudb from "./src/buitsudb.js";
import buitsuexpress from "./src/buitsuexpress.js";
//! dotenv + config
//? entries in dotenv override config where applicable
dotenv.config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const __config = path.join(__dirname, (process.env.buitsu_config || "private/config.yml"));
if (!fs.existsSync(__config)) {
console.error(`Config "${__config}" must exist!`);
process.exit(1);
}
const c = yaml.parse(fs.readFileSync(__config, "utf8"));
//! open/setup DB
const db = new buitsudb(c.database);
db.open();
db.setup();
//! open express!
const server = new buitsuexpress(c.express, db);
server.open();
//! cleanup
function shutdown() {
//? make sure we treat the DB nicely... >_>
db.close();
server.close(() => process.exit(1), () => process.exit(0));
}
process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);