forked from NodeBB/NodeBB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprestart.js
106 lines (89 loc) · 3.04 KB
/
prestart.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'use strict';
var nconf = require('nconf');
var url = require('url');
var winston = require('winston');
var path = require('path');
var pkg = require('../package.json');
var dirname = require('./cli/paths').baseDir;
function setupWinston() {
if (!winston.format) {
return;
}
var formats = [];
if (nconf.get('log-colorize') !== 'false') {
formats.push(winston.format.colorize());
}
if (nconf.get('json-logging')) {
formats.push(winston.format.timestamp());
formats.push(winston.format.json());
} else {
const timestampFormat = winston.format((info) => {
var dateString = new Date().toISOString() + ' [' + nconf.get('port') + '/' + global.process.pid + ']';
info.level = dateString + ' - ' + info.level;
return info;
});
formats.push(timestampFormat());
formats.push(winston.format.splat());
formats.push(winston.format.simple());
}
winston.configure({
level: nconf.get('log-level') || (global.env === 'production' ? 'info' : 'verbose'),
format: winston.format.combine.apply(null, formats),
transports: [
new winston.transports.Console({
handleExceptions: true,
}),
],
});
}
function loadConfig(configFile) {
nconf.file({
file: configFile,
});
nconf.defaults({
base_dir: dirname,
themes_path: path.join(dirname, 'node_modules'),
upload_path: 'public/uploads',
views_dir: path.join(dirname, 'build/public/templates'),
version: pkg.version,
});
if (!nconf.get('isCluster')) {
nconf.set('isPrimary', 'true');
nconf.set('isCluster', 'false');
}
var isPrimary = nconf.get('isPrimary');
nconf.set('isPrimary', isPrimary === undefined ? 'true' : isPrimary);
// Ensure themes_path is a full filepath
nconf.set('themes_path', path.resolve(dirname, nconf.get('themes_path')));
nconf.set('core_templates_path', path.join(dirname, 'src/views'));
nconf.set('base_templates_path', path.join(nconf.get('themes_path'), 'nodebb-theme-persona/templates'));
nconf.set('upload_path', path.resolve(nconf.get('base_dir'), nconf.get('upload_path')));
nconf.set('upload_url', '/assets/uploads');
if (nconf.get('url')) {
nconf.set('url_parsed', url.parse(nconf.get('url')));
}
// Explicitly cast 'jobsDisabled' as Bool
var castAsBool = ['jobsDisabled'];
nconf.stores.env.readOnly = false;
castAsBool.forEach(function (prop) {
var value = nconf.get(prop);
if (value) {
nconf.set(prop, typeof value === 'boolean' ? value : String(value).toLowerCase() === 'true');
}
});
nconf.stores.env.readOnly = true;
nconf.set('runJobs', nconf.get('isPrimary') === 'true' && !nconf.get('jobsDisabled'));
}
function versionCheck() {
var version = process.version.slice(1);
var range = pkg.engines.node;
var semver = require('semver');
var compatible = semver.satisfies(version, range);
if (!compatible) {
winston.warn('Your version of Node.js is too outdated for NodeBB. Please update your version of Node.js.');
winston.warn('Recommended ' + range.green + ', '.reset + version.yellow + ' provided\n'.reset);
}
}
exports.setupWinston = setupWinston;
exports.loadConfig = loadConfig;
exports.versionCheck = versionCheck;