Добавил сохранение и загрузку конфига
This commit is contained in:
32
server/config/configSaver.js
Normal file
32
server/config/configSaver.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const fs = require('fs-extra');
|
||||
const _ = require('lodash');
|
||||
|
||||
const propsToSave = [
|
||||
'servers'
|
||||
];
|
||||
|
||||
async function load(config, configFilename) {
|
||||
if (!configFilename) {
|
||||
configFilename = `${config.dataDir}/config.json`;
|
||||
|
||||
if (!await fs.pathExists(configFilename)) {
|
||||
save(config);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const data = await fs.readFile(configFilename, 'utf8');
|
||||
Object.assign(config, JSON.parse(data));
|
||||
}
|
||||
|
||||
async function save(config) {
|
||||
const configFilename = `${config.dataDir}/config.json`;
|
||||
const dataToSave = _.pick(config, propsToSave);
|
||||
|
||||
await fs.writeFile(configFilename, JSON.stringify(dataToSave, null, 4));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
load,
|
||||
save
|
||||
};
|
||||
@@ -1,9 +1,11 @@
|
||||
const config = require('./config');
|
||||
|
||||
const {initLogger, getLog} = require('./core/getLogger');
|
||||
initLogger(config);
|
||||
const log = getLog();
|
||||
|
||||
const configSaver = require('./config/configSaver');
|
||||
const argv = require('minimist')(process.argv.slice(2));
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
@@ -23,15 +25,17 @@ async function init() {
|
||||
await fs.remove(appDir);
|
||||
await fs.move(appNewDir, appDir);
|
||||
}
|
||||
|
||||
//загружаем конфиг из файла
|
||||
await configSaver.load(config, argv.config);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const connPool = new SqliteConnectionPool(20, config);
|
||||
|
||||
log('Initializing');
|
||||
await init();
|
||||
|
||||
log('Opening database');
|
||||
const connPool = new SqliteConnectionPool(20, config);
|
||||
await connPool.init();
|
||||
|
||||
//servers
|
||||
@@ -42,7 +46,7 @@ async function main() {
|
||||
|
||||
let devModule = undefined;
|
||||
if (serverConfig.branch == 'development') {
|
||||
const devFileName = './dev.js'; //ignored by pkg -50Mb executable size
|
||||
const devFileName = './dev.js'; //require ignored by pkg -50Mb executable size
|
||||
devModule = require(devFileName);
|
||||
devModule.webpackDevMiddleware(app);
|
||||
}
|
||||
@@ -80,4 +84,12 @@ async function main() {
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
(async() => {
|
||||
try {
|
||||
await main();
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user