|
@@ -6,16 +6,18 @@ const compression = require('compression');
|
|
const http = require('http');
|
|
const http = require('http');
|
|
const WebSocket = require ('ws');
|
|
const WebSocket = require ('ws');
|
|
|
|
|
|
-const ayncExit = new (require('./core/AsyncExit'))();
|
|
|
|
|
|
+const RemoteLib = require('./core/RemoteLib');//singleton
|
|
const utils = require('./core/utils');
|
|
const utils = require('./core/utils');
|
|
|
|
|
|
|
|
+const ayncExit = new (require('./core/AsyncExit'))();
|
|
|
|
+
|
|
const maxPayloadSize = 50;//in MB
|
|
const maxPayloadSize = 50;//in MB
|
|
|
|
|
|
let log;
|
|
let log;
|
|
let config;
|
|
let config;
|
|
let argv;
|
|
let argv;
|
|
let branch = '';
|
|
let branch = '';
|
|
-const argvStrings = ['lib-dir', 'inpx'];
|
|
|
|
|
|
+const argvStrings = ['lib-dir', 'app-dir', 'inpx'];
|
|
|
|
|
|
function showHelp() {
|
|
function showHelp() {
|
|
console.log(utils.versionText(config));
|
|
console.log(utils.versionText(config));
|
|
@@ -24,6 +26,7 @@ function showHelp() {
|
|
|
|
|
|
Options:
|
|
Options:
|
|
--help Print ${config.name} command line options
|
|
--help Print ${config.name} command line options
|
|
|
|
+ --app-dir=<dirpath> Set application working directory, default: "<execDir>/.${config.name}"
|
|
--lib-dir=<dirpath> Set library directory, default: the same as ${config.name} executable's
|
|
--lib-dir=<dirpath> Set library directory, default: the same as ${config.name} executable's
|
|
--inpx=<filepath> Set INPX collection file, default: the one that found in library dir
|
|
--inpx=<filepath> Set INPX collection file, default: the one that found in library dir
|
|
--recreate Force recreation of the search database on start
|
|
--recreate Force recreation of the search database on start
|
|
@@ -33,25 +36,30 @@ Options:
|
|
|
|
|
|
async function init() {
|
|
async function init() {
|
|
argv = require('minimist')(process.argv.slice(2), {string: argvStrings});
|
|
argv = require('minimist')(process.argv.slice(2), {string: argvStrings});
|
|
|
|
+ const dataDir = argv['app-dir'];
|
|
|
|
|
|
//config
|
|
//config
|
|
const configManager = new (require('./config'))();//singleton
|
|
const configManager = new (require('./config'))();//singleton
|
|
- await configManager.init();
|
|
|
|
- //configManager.userConfigFile = argv.config;
|
|
|
|
|
|
+ await configManager.init(dataDir);
|
|
await configManager.load();
|
|
await configManager.load();
|
|
config = configManager.config;
|
|
config = configManager.config;
|
|
branch = config.branch;
|
|
branch = config.branch;
|
|
|
|
|
|
- //logger
|
|
|
|
- const appLogger = new (require('./core/AppLogger'))();//singleton
|
|
|
|
- await appLogger.init(config);
|
|
|
|
- log = appLogger.log;
|
|
|
|
-
|
|
|
|
//dirs
|
|
//dirs
|
|
|
|
+ config.tempDir = `${config.dataDir}/tmp`;
|
|
|
|
+ config.logDir = `${config.dataDir}/log`;
|
|
|
|
+ config.publicDir = `${config.dataDir}/public`;
|
|
|
|
+ configManager.config = config;
|
|
|
|
+
|
|
await fs.ensureDir(config.dataDir);
|
|
await fs.ensureDir(config.dataDir);
|
|
await fs.ensureDir(config.tempDir);
|
|
await fs.ensureDir(config.tempDir);
|
|
await fs.emptyDir(config.tempDir);
|
|
await fs.emptyDir(config.tempDir);
|
|
|
|
|
|
|
|
+ //logger
|
|
|
|
+ const appLogger = new (require('./core/AppLogger'))();//singleton
|
|
|
|
+ await appLogger.init(config);
|
|
|
|
+ log = appLogger.log;
|
|
|
|
+
|
|
//web app
|
|
//web app
|
|
if (branch !== 'development') {
|
|
if (branch !== 'development') {
|
|
const createWebApp = require('./createWebApp');
|
|
const createWebApp = require('./createWebApp');
|
|
@@ -67,52 +75,49 @@ async function init() {
|
|
log('Initializing');
|
|
log('Initializing');
|
|
}
|
|
}
|
|
|
|
|
|
- const libDir = argv['lib-dir'];
|
|
|
|
- if (libDir) {
|
|
|
|
- if (await fs.pathExists(libDir)) {
|
|
|
|
- config.libDir = libDir;
|
|
|
|
|
|
+ if (!config.remoteLib) {
|
|
|
|
+ const libDir = argv['lib-dir'];
|
|
|
|
+ if (libDir) {
|
|
|
|
+ if (await fs.pathExists(libDir)) {
|
|
|
|
+ config.libDir = libDir;
|
|
|
|
+ } else {
|
|
|
|
+ throw new Error(`Directory "${libDir}" not exists`);
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- throw new Error(`Directory "${libDir}" not exists`);
|
|
|
|
|
|
+ config.libDir = config.execDir;
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- config.libDir = config.execDir;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if (argv.inpx) {
|
|
|
|
- if (await fs.pathExists(argv.inpx)) {
|
|
|
|
- config.inpxFile = argv.inpx;
|
|
|
|
- } else {
|
|
|
|
- throw new Error(`File "${argv.inpx}" not found`);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- const inpxFiles = [];
|
|
|
|
- await utils.findFiles((file) => {
|
|
|
|
- if (path.extname(file) == '.inpx')
|
|
|
|
- inpxFiles.push(file);
|
|
|
|
- }, config.libDir, false);
|
|
|
|
-
|
|
|
|
- if (inpxFiles.length) {
|
|
|
|
- if (inpxFiles.length == 1) {
|
|
|
|
- config.inpxFile = inpxFiles[0];
|
|
|
|
|
|
+ if (argv.inpx) {
|
|
|
|
+ if (await fs.pathExists(argv.inpx)) {
|
|
|
|
+ config.inpxFile = argv.inpx;
|
|
} else {
|
|
} else {
|
|
- throw new Error(`Found more than one .inpx files: \n${inpxFiles.join('\n')}`);
|
|
|
|
|
|
+ throw new Error(`File "${argv.inpx}" not found`);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- throw new Error(`No .inpx files found here: ${config.libDir}`);
|
|
|
|
|
|
+ const inpxFiles = [];
|
|
|
|
+ await utils.findFiles((file) => {
|
|
|
|
+ if (path.extname(file) == '.inpx')
|
|
|
|
+ inpxFiles.push(file);
|
|
|
|
+ }, config.libDir, false);
|
|
|
|
+
|
|
|
|
+ if (inpxFiles.length) {
|
|
|
|
+ if (inpxFiles.length == 1) {
|
|
|
|
+ config.inpxFile = inpxFiles[0];
|
|
|
|
+ } else {
|
|
|
|
+ throw new Error(`Found more than one .inpx files: \n${inpxFiles.join('\n')}`);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ throw new Error(`No .inpx files found here: ${config.libDir}`);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ const remoteLib = new RemoteLib(config);
|
|
|
|
+ config.inpxFile = await remoteLib.getInpxFile();
|
|
}
|
|
}
|
|
|
|
|
|
config.recreateDb = argv.recreate || false;
|
|
config.recreateDb = argv.recreate || false;
|
|
config.inpxFilterFile = `${config.execDir}/inpx-web-filter.json`;
|
|
config.inpxFilterFile = `${config.execDir}/inpx-web-filter.json`;
|
|
config.allowUnsafeFilter = argv['unsafe-filter'] || false;
|
|
config.allowUnsafeFilter = argv['unsafe-filter'] || false;
|
|
-
|
|
|
|
- //app
|
|
|
|
- const appDir = `${config.publicDir}/app`;
|
|
|
|
- const appNewDir = `${config.publicDir}/app_new`;
|
|
|
|
- if (await fs.pathExists(appNewDir)) {
|
|
|
|
- await fs.remove(appDir);
|
|
|
|
- await fs.move(appNewDir, appDir);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
async function main() {
|
|
async function main() {
|
|
@@ -124,10 +129,8 @@ async function main() {
|
|
const server = http.createServer(app);
|
|
const server = http.createServer(app);
|
|
const wss = new WebSocket.Server({ server, maxPayload: maxPayloadSize*1024*1024 });
|
|
const wss = new WebSocket.Server({ server, maxPayload: maxPayloadSize*1024*1024 });
|
|
|
|
|
|
- const serverConfig = Object.assign({}, config, config.server);
|
|
|
|
-
|
|
|
|
let devModule = undefined;
|
|
let devModule = undefined;
|
|
- if (serverConfig.branch == 'development') {
|
|
|
|
|
|
+ if (branch == 'development') {
|
|
const devFileName = './dev.js'; //require ignored by pkg -50Mb executable size
|
|
const devFileName = './dev.js'; //require ignored by pkg -50Mb executable size
|
|
devModule = require(devFileName);
|
|
devModule = require(devFileName);
|
|
devModule.webpackDevMiddleware(app);
|
|
devModule.webpackDevMiddleware(app);
|
|
@@ -152,6 +155,7 @@ async function main() {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ const serverConfig = config.server;
|
|
server.listen(serverConfig.port, serverConfig.ip, () => {
|
|
server.listen(serverConfig.port, serverConfig.ip, () => {
|
|
log(`Server is ready on http://${serverConfig.ip}:${serverConfig.port}`);
|
|
log(`Server is ready on http://${serverConfig.ip}:${serverConfig.port}`);
|
|
});
|
|
});
|