diff options
Diffstat (limited to 'initializers/checker.js')
-rw-r--r-- | initializers/checker.js | 84 |
1 files changed, 41 insertions, 43 deletions
diff --git a/initializers/checker.js b/initializers/checker.js index f4458c5cf..9a7d04ed4 100644 --- a/initializers/checker.js +++ b/initializers/checker.js | |||
@@ -1,50 +1,48 @@ | |||
1 | ;(function () { | 1 | 'use strict' |
2 | 'use strict' | 2 | |
3 | 3 | var config = require('config') | |
4 | var config = require('config') | 4 | var mkdirp = require('mkdirp') |
5 | var mkdirp = require('mkdirp') | 5 | var path = require('path') |
6 | var path = require('path') | 6 | |
7 | 7 | var checker = { | |
8 | var checker = { | 8 | checkConfig: checkConfig, |
9 | checkConfig: checkConfig, | 9 | createDirectoriesIfNotExist: createDirectoriesIfNotExist |
10 | createDirectoriesIfNotExist: createDirectoriesIfNotExist | 10 | } |
11 | } | 11 | |
12 | 12 | // Check the config files | |
13 | // Check the config files | 13 | function checkConfig () { |
14 | function checkConfig () { | 14 | var required = [ 'listen.port', |
15 | var required = [ 'listen.port', | 15 | 'webserver.https', 'webserver.host', 'webserver.port', |
16 | 'webserver.https', 'webserver.host', 'webserver.port', | 16 | 'database.host', 'database.port', 'database.suffix', |
17 | 'database.host', 'database.port', 'database.suffix', | 17 | 'storage.certs', 'storage.uploads', 'storage.logs', |
18 | 'storage.certs', 'storage.uploads', 'storage.logs', | 18 | 'network.friends' ] |
19 | 'network.friends' ] | 19 | var miss = [] |
20 | var miss = [] | 20 | |
21 | 21 | for (var key of required) { | |
22 | for (var key of required) { | 22 | if (!config.has(key)) { |
23 | if (!config.has(key)) { | 23 | miss.push(key) |
24 | miss.push(key) | ||
25 | } | ||
26 | } | 24 | } |
27 | |||
28 | return miss | ||
29 | } | 25 | } |
30 | 26 | ||
31 | // Create directories for the storage if it doesn't exist | 27 | return miss |
32 | function createDirectoriesIfNotExist () { | 28 | } |
33 | var storages = config.get('storage') | 29 | |
34 | 30 | // Create directories for the storage if it doesn't exist | |
35 | for (var key of Object.keys(storages)) { | 31 | function createDirectoriesIfNotExist () { |
36 | var dir = storages[key] | 32 | var storages = config.get('storage') |
37 | try { | 33 | |
38 | mkdirp.sync(path.join(__dirname, '..', dir)) | 34 | for (var key of Object.keys(storages)) { |
39 | } catch (error) { | 35 | var dir = storages[key] |
40 | // Do not use logger | 36 | try { |
41 | console.error('Cannot create ' + path + ':' + error) | 37 | mkdirp.sync(path.join(__dirname, '..', dir)) |
42 | process.exit(0) | 38 | } catch (error) { |
43 | } | 39 | // Do not use logger |
40 | console.error('Cannot create ' + path + ':' + error) | ||
41 | process.exit(0) | ||
44 | } | 42 | } |
45 | } | 43 | } |
44 | } | ||
46 | 45 | ||
47 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
48 | 47 | ||
49 | module.exports = checker | 48 | module.exports = checker |
50 | })() | ||