-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.js
58 lines (47 loc) · 1.53 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const _ = require('lodash');
const path = require('path');
const fse = require('fs-extra');
const os = require('os');
const hbs = require('hbs');
const clarg = require('clarg');
const clOpts = clarg().opts;
const appPortRaw = clOpts.port || clOpts.p;
const appPortParsed = parseInt(appPortRaw, 10);
const appPort = (appPortRaw == appPortParsed) ? appPortParsed : 3000; // eslint-disable-line eqeqeq
const appNetworkRaw = (clOpts.network || clOpts.n || '').trim();
const appNetwork = ['public', 'private'].indexOf(appNetworkRaw) === -1 ? 'local' : appNetworkRaw;
const networks = {
public: '0',
local: '127.0.0.1'
};
// fixing for DO setup
const privateInterface = os.networkInterfaces().eth1;
if (privateInterface) {
networks.private = _.map(_.find(privateInterface, { family: 'IPv4' }), 'address');
}
const appNetworkInterface = networks[appNetwork];
const config = {
baseUrl: clOpts.url || clOpts.u || `http://localhost:${appPort}`,
appPort,
appNetwork,
appNetworkInterface,
mongoUrl: clOpts.mongoUrl || clOpts.mongourl || clOpts.mongo,
memcache: clOpts.memcache || 30 * 60000, // 30 minutes
paths: {
public: path.join(__dirname, 'public'),
views: path.join(__dirname, 'views'),
data: path.join(__dirname, 'data'),
logfile: path.join(__dirname, 'requestlog.json')
}
};
config.views = {
engine: hbs,
partialsPath: `${config.paths.views}/partials`
};
// ensure request log file
try {
fse.accessSync(config.paths.logfile);
} catch (e) {
fse.writeJsonSync(config.paths.logfile, {});
}
module.exports = config;