-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathconfig.js
More file actions
86 lines (69 loc) · 2.73 KB
/
config.js
File metadata and controls
86 lines (69 loc) · 2.73 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// **********************************************************************************
// Websocket server backend for the RaspberryPi-Gateway App
// http://lowpowerlab.com/gateway
// **********************************************************************************
// Common application configuration settings.
// **********************************************************************************
const JSON5 = require('json5'); // https://github.com/aseemk/json5
const nconf = require('nconf'); // https://github.com/indexzero/nconf
const path = require('path');
exports.load = function({defaultStateDir = __dirname, defaultContentDir = null} = {}) {
nconf.argv().env()
const stateDir = path.normalize(nconf.get('MOTEINO_GATEWAY_STATE_DIRECTORY') || defaultStateDir);
const resolvePath = (base) => (...dirs) => path.resolve(base, ...dirs);
const resolveCoreStatePath = resolvePath(defaultStateDir);
const resolveUserStatePath = resolvePath(stateDir);
const coreContentDir = resolveCoreStatePath('www');
const contentDir = path.normalize(nconf.get('MOTEINO_GATEWAY_CONTENT_DIRECTORY') || defaultContentDir || coreContentDir);
const resolveCoreContentPath = resolvePath(coreContentDir);
const resolveUserContentPath = resolvePath(contentDir);
const coreImagesDir = resolveCoreContentPath('images');
const userImagesDir = resolveUserContentPath('images');
const coreMetricsDir = resolveCoreStatePath('metrics');
const userMetricsDir = resolveUserStatePath('metrics');
const dbDir = resolveUserStatePath('data/db');
if (stateDir == defaultStateDir)
{
nconf.file('mutable5', {
file: resolveCoreStatePath('settings.json5'),
format: JSON5,
});
nconf.file('mutable', {
file: resolveCoreStatePath('settings.json'),
});
}
else
{
nconf.file('mutable5', {
file: resolveUserStatePath('settings.json5'),
format: JSON5,
});
nconf.file('mutable', {
file: resolveUserStatePath('settings.json'),
});
nconf.file('immutable5', {
file: resolveCoreStatePath('settings.json5'),
format: JSON5,
});
nconf.file('immutable', {
file: resolveCoreStatePath('settings.json'),
});
}
return {
'nconf': nconf,
'stateDir': stateDir,
'contentDir': contentDir,
'coreContentDir': coreContentDir,
'coreImagesDir': coreImagesDir,
'userImagesDir': userImagesDir,
'coreMetricsDir': coreMetricsDir,
'userMetricsDir': userMetricsDir,
'dbDir': dbDir,
'resolveCoreContentPath': resolveCoreContentPath,
'resolveCoreStatePath': resolveCoreStatePath,
'resolveUserContentPath': resolveUserContentPath,
'resolveUserStatePath': resolveUserStatePath,
};
};
// Load configuration and export it
Object.assign(exports, exports.load());