docker build

This commit is contained in:
Jan Prochazka
2020-03-15 21:10:38 +01:00
parent 3a8c961920
commit 27a323f557
7 changed files with 66 additions and 56 deletions

View File

@@ -1,15 +1,15 @@
const os = require('os');
const path = require('path');
const fs = require('fs-extra');
const fs = require('fs');
let created = false;
module.exports = async function datadir() {
module.exports = function datadir() {
const dir = path.join(os.homedir(), 'dbgate-data');
if (!created) {
const stat = await fs.stat(dir);
if (!stat.isDirectory) {
await fs.mkdir(dir);
if (!fs.existsSync(dir)) {
console.log(`Creating data directory ${dir}`)
fs.mkdirSync(dir);
}
created = true;
}

View File

@@ -7,6 +7,16 @@ const express = require('express');
module.exports = function useController(app, route, controller) {
const router = express.Router();
if (controller._init) {
console.log(`Calling init controller for controller ${route}`);
try {
controller._init();
} catch (err) {
console.log(`Error initializing controller, exiting application`, err);
process.exit(1);
}
}
for (const key of _.keys(controller)) {
const obj = controller[key];
if (!_.isFunction(obj)) continue;
@@ -31,10 +41,10 @@ module.exports = function useController(app, route, controller) {
router[method](route, controller[key]);
} else {
router[method](route, async (req, res) => {
if (controller._init && !controller._init_called) {
await controller._init();
controller._init_called = true;
}
// if (controller._init && !controller._init_called) {
// await controller._init();
// controller._init_called = true;
// }
try {
let params = [{ ...req.body, ...req.query }];
if (rawParams) params = [req, res];