From 799ace06d7f9ddcccd735d190405e3d747eaf81f Mon Sep 17 00:00:00 2001 From: Tau Date: Mon, 14 Oct 2019 22:49:36 -0400 Subject: [PATCH] Wire up schema automation --- src/index.ts | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3670015..a9b7999 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ import net from "net"; import aimedb from "./aimedb"; import allnet from "./allnet"; import billing from "./billing"; +import checkdb from "./checkdb"; import chunithm from "./chunithm"; import diva from "./diva"; import idz from "./idz"; @@ -15,26 +16,36 @@ import idzPing from "./idz/ping"; import { openSqlite } from "./sql"; import * as Swb from "./switchboard"; -fs.mkdirSync("./data", { recursive: true }); +(async function() { + fs.mkdirSync("./data", { recursive: true }); -const db = openSqlite("./data/db.sqlite3"); + const db = openSqlite("./data/db.sqlite3"); -const tls = { - cert: fs.readFileSync("pki/server.pem"), - key: fs.readFileSync("pki/server.key"), -}; + try { + await checkdb(db); + } catch (e) { + console.error(e); -net.createServer(aimedb(db)).listen(Swb.PORT_AIMEDB, Swb.HOST_INT); -http.createServer(allnet).listen(Swb.PORT_ALLNET, Swb.HOST_INT); -https.createServer(tls, billing).listen(Swb.PORT_BILLING, Swb.HOST_INT); + return; + } -http.createServer(chunithm).listen(Swb.PORT_CHUNITHM, Swb.HOST_INT); -http.createServer(diva).listen(Swb.PORT_DIVA, Swb.HOST_INT); + const tls = { + cert: fs.readFileSync("pki/server.pem"), + key: fs.readFileSync("pki/server.key"), + }; -net.createServer(idz(db)).listen(Swb.PORT_IDZ.USERDB.TCP, Swb.HOST_INT); -idzPing(10001, Swb.HOST_INT); // ?? tbd -idzPing(Swb.PORT_IDZ.MATCH.UDP_SEND, Swb.HOST_INT); -idzPing(Swb.PORT_IDZ.ECHO1, Swb.HOST_INT); -idzPing(Swb.PORT_IDZ.ECHO2, Swb.HOST_INT); + net.createServer(aimedb(db)).listen(Swb.PORT_AIMEDB, Swb.HOST_INT); + http.createServer(allnet).listen(Swb.PORT_ALLNET, Swb.HOST_INT); + https.createServer(tls, billing).listen(Swb.PORT_BILLING, Swb.HOST_INT); -console.log("Startup OK"); + http.createServer(chunithm).listen(Swb.PORT_CHUNITHM, Swb.HOST_INT); + http.createServer(diva).listen(Swb.PORT_DIVA, Swb.HOST_INT); + + net.createServer(idz(db)).listen(Swb.PORT_IDZ.USERDB.TCP, Swb.HOST_INT); + idzPing(10001, Swb.HOST_INT); // ?? tbd + idzPing(Swb.PORT_IDZ.MATCH.UDP_SEND, Swb.HOST_INT); + idzPing(Swb.PORT_IDZ.ECHO1, Swb.HOST_INT); + idzPing(Swb.PORT_IDZ.ECHO2, Swb.HOST_INT); + + console.log("Startup OK"); +})();