aboutsummaryrefslogtreecommitdiff
path: root/src/index.js
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2020-04-07 14:17:24 -0500
committerMark Powers <markppowers0@gmail.com>2020-04-07 14:17:24 -0500
commit1bffb064e2414ced5b1924a4f9fbd822a09c718e (patch)
treef0e4a0a8d9a6f4f58619329bf408fe9bf7d1dd4c /src/index.js
Initial commit
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/index.js b/src/index.js
new file mode 100644
index 0000000..647bf3e
--- /dev/null
+++ b/src/index.js
@@ -0,0 +1,64 @@
+const server = require('./server');
+const Sequelize = require('sequelize');
+const fs = require('fs');
+const path = require('path');
+const jwt = require('jsonwebtoken');
+
+
+const config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')));
+
+const dbCreds = config.database;
+const secret = config.jwt_secret;
+
+const jwtFunctions = {
+ sign: function (message) {
+ return jwt.sign({ value: message }, secret);
+ },
+ verify: function (token) {
+ return jwt.verify(token, secret).value;
+ }
+}
+
+const database = new Sequelize(dbCreds.database, undefined, undefined, {
+ logging(str) {
+ console.debug(`DB:${str}`);
+ },
+ dialectOptions: {
+ charset: 'utf8mb4',
+ multipleStatements: true,
+ },
+ storage: './database.sqlite',
+ dialect: 'sqlite',
+ pool: {
+ max: 5,
+ min: 0,
+ idle: 10000,
+ },
+});
+
+database.authenticate().then(() => {
+ console.debug(`database connection successful: ${dbCreds.database}`);
+}, (e) => console.log(e));
+
+async function sync(alter, force, callback) {
+ await database.sync({ alter, force, logging: console.log });
+}
+
+function setUpModels() {
+ const models = {
+ }
+ return models;
+}
+
+const models = setUpModels();
+sync();
+
+server.setUpRoutes(models, jwtFunctions, database);
+server.load("./ur/server", models, jwtFunctions, database)
+server.load("./quadrowple/server", models, jwtFunctions, database)
+server.load("./snake/server", models, jwtFunctions, database)
+server.load("./stacker/server", models, jwtFunctions, database)
+server.load("./pinball/server", models, jwtFunctions, database)
+server.load("./math/server", models, jwtFunctions, database)
+server.listen(config.port);
+