Commit | Line | Data |
---|---|---|
e118beaa JB |
1 | import ConfigurationData, { StationTemplateURL } from '../types/ConfigurationData'; |
2 | ||
6af9012e | 3 | import Utils from './Utils'; |
3f40bc9c | 4 | import fs from 'fs'; |
7dde0b73 | 5 | |
3f40bc9c | 6 | export default class Configuration { |
e118beaa | 7 | static configuration: ConfigurationData; |
83ee6a86 | 8 | |
7dde0b73 | 9 | // Read the config file |
e118beaa | 10 | static getConfig(): ConfigurationData { |
868cb6d1 | 11 | if (!Configuration.configuration) { |
e118beaa | 12 | Configuration.configuration = JSON.parse(fs.readFileSync('./src/assets/config.json', 'utf8')) as ConfigurationData; |
83ee6a86 | 13 | } |
868cb6d1 | 14 | return Configuration.configuration; |
7dde0b73 JB |
15 | } |
16 | ||
a4a21709 | 17 | static getStatisticsDisplayInterval(): number { |
7dde0b73 | 18 | // Read conf |
2e6f5966 | 19 | return Utils.objectHasOwnProperty(Configuration.getConfig(), 'statisticsDisplayInterval') ? Configuration.getConfig().statisticsDisplayInterval : 60; |
7dde0b73 JB |
20 | } |
21 | ||
a4a21709 | 22 | static getAutoReconnectTimeout(): number { |
7dde0b73 | 23 | // Read conf |
1d7ca20c | 24 | return Utils.objectHasOwnProperty(Configuration.getConfig(), 'autoReconnectTimeout') ? Configuration.getConfig().autoReconnectTimeout : 10; |
7dde0b73 JB |
25 | } |
26 | ||
a4a21709 | 27 | static getAutoReconnectMaxRetries(): number { |
7dde0b73 | 28 | // Read conf |
1d7ca20c | 29 | return Utils.objectHasOwnProperty(Configuration.getConfig(), 'autoReconnectMaxRetries') ? Configuration.getConfig().autoReconnectMaxRetries : -1; |
7dde0b73 JB |
30 | } |
31 | ||
e118beaa | 32 | static getStationTemplateURLs(): StationTemplateURL[] { |
7dde0b73 JB |
33 | // Read conf |
34 | return Configuration.getConfig().stationTemplateURLs; | |
35 | } | |
36 | ||
a4a21709 | 37 | static useWorkerPool(): boolean { |
7dde0b73 JB |
38 | return Configuration.getConfig().useWorkerPool; |
39 | } | |
40 | ||
a4a21709 | 41 | static getWorkerPoolSize(): number { |
7dde0b73 JB |
42 | return Configuration.getConfig().workerPoolSize; |
43 | } | |
44 | ||
7ec46a9a JB |
45 | static getLogConsole(): boolean { |
46 | return Utils.objectHasOwnProperty(Configuration.getConfig(), 'logConsole') ? Configuration.getConfig().logConsole : false; | |
7dde0b73 JB |
47 | } |
48 | ||
a4a21709 | 49 | static getLogFormat(): string { |
027b409a JB |
50 | return Utils.objectHasOwnProperty(Configuration.getConfig(), 'logFormat') ? Configuration.getConfig().logFormat : 'simple'; |
51 | } | |
52 | ||
a4a21709 | 53 | static getLogLevel(): string { |
2e6f5966 JB |
54 | return Utils.objectHasOwnProperty(Configuration.getConfig(), 'logLevel') ? Configuration.getConfig().logLevel : 'info'; |
55 | } | |
56 | ||
a4a21709 | 57 | static getLogFile(): string { |
1d7ca20c | 58 | return Utils.objectHasOwnProperty(Configuration.getConfig(), 'logFile') ? Configuration.getConfig().logFile : 'combined.log'; |
7dde0b73 JB |
59 | } |
60 | ||
7ec46a9a JB |
61 | static getLogErrorFile(): string { |
62 | return Utils.objectHasOwnProperty(Configuration.getConfig(), 'logErrorFile') ? Configuration.getConfig().logErrorFile : 'error.log'; | |
7dde0b73 JB |
63 | } |
64 | ||
e118beaa | 65 | static getSupervisionURLs(): string[] { |
7dde0b73 JB |
66 | // Read conf |
67 | return Configuration.getConfig().supervisionURLs; | |
68 | } | |
69 | ||
524d9cb3 JB |
70 | static getDistributeStationsToTenantsEqually(): boolean { |
71 | return Utils.objectHasOwnProperty(Configuration.getConfig(), 'distributeStationsToTenantsEqually') ? Configuration.getConfig().distributeStationsToTenantsEqually : true; | |
7dde0b73 JB |
72 | } |
73 | } |