Skip to content

Commit

Permalink
upd db config init, changed mysql conn promise
Browse files Browse the repository at this point in the history
  • Loading branch information
SorenEricMent committed Jul 10, 2022
1 parent e4edf08 commit 7e83b82
Show file tree
Hide file tree
Showing 31 changed files with 68 additions and 2,657 deletions.
2 changes: 1 addition & 1 deletion install.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "ioredis";
import {default as inquirer} from "inquirer";
import {isModuleAvailable} from "./modules/utils.mjs";

const moduleList = ["mysql2", "ioredis", "inquirer","express","redis-json"];
const moduleList = ["mysql2", "ioredis", "inquirer","express"];

function install(){
console.log("******************************");
Expand Down
31 changes: 23 additions & 8 deletions modules/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { fileURLToPath } from "url";
import { readFileSync } from "fs";
import { outputLogsColored, outputLogs } from "./utils.mjs";
import { default as mysql } from "mysql2";
import { default as redis} from "ioredis";
import { default as redis } from "ioredis";
import { promisifiedMysqlConnect, promisifiedRedisConnect } from "./utils.mjs";


function MysqlIntegrityCheck(mysqlConnection) {
return new Promise((resolve, reject) => {

resolve();
});
}

Expand Down Expand Up @@ -63,12 +63,27 @@ function initializeBlorumServer() {
}).then(function () {
log("log", "INIT:db/redis", "Successfully connected to Redis Server");
});
let mysqlPromise = promisifiedMysqlConnect(mysqlConnection);
mysqlPromise.catch(function (err) {
log("error", "INIT:db/mysql", "Failed to connect to MySQL Server");
throw err;
}).then(function () {
log("log", "INIT:db/mysql", "Successfully connected to MySQL Server");
let mysqlPromise = new Promise((resolve, reject) => {
promisifiedMysqlConnect(mysqlConnection).then(function (conn) {
log("log", "INIT:db/mysql", "Successfully connected to MySQL Server");
MysqlIntegrityCheck(conn).then(function () {
conn.query("SELECT * FROM config;", function (err, result) {
if (err) {
throw err;
}
resolve({
"mysql": mysqlConnection,
"site_config": result
});
});
}).catch(function (err) {
log("error", "INIT:db/mysql", "MySQL database integrity check failed.");
throw err;
});
}).catch(function (err) {
log("error", "INIT:db/mysql", "Failed to connect to MySQL Server");
throw err;
});
});
return {
"bootConfig": bootConfig,
Expand Down
7 changes: 4 additions & 3 deletions modules/router.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function initializeRouter(db,log,salt){
"X-Powered-By": "Blorum",
"Access-Control-Allow-Origin": "*"
};

blorumRouter.use(express.json());

blorumRouter.get('/', function (req, res) {
res.set("Content-Type","application/json");
res.set(commonHeader);
Expand All @@ -27,14 +28,14 @@ function initializeRouter(db,log,salt){
});

blorumRouter.post('/user/register', function (req, res) {
console.log(req,res);
console.log(req.body);
res.set("Content-Type","application/json");
res.set(commonHeader);
res.status(200).send();
});

blorumRouter.post('/user/logout', function (req, res) {
console.log(req,res);
console.log(req);
res.set("Content-Type","application/json");
res.set(commonHeader);
res.status(200).send();
Expand Down
2 changes: 1 addition & 1 deletion modules/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "crypto";
import {default as Redis} from "ioredis";
import Redis from "ioredis";

const version = "1.0.0 in_dev (unf, debug) dv 10001";

Expand Down
8 changes: 0 additions & 8 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 0 additions & 72 deletions node_modules/redis-json/CHANGELOG.md

This file was deleted.

21 changes: 0 additions & 21 deletions node_modules/redis-json/LICENSE

This file was deleted.

163 changes: 0 additions & 163 deletions node_modules/redis-json/README.md

This file was deleted.

Loading

0 comments on commit 7e83b82

Please sign in to comment.