-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ts
114 lines (108 loc) · 2.29 KB
/
config.ts
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
107
108
109
110
111
112
113
114
import * as convict from 'convict';
import { realpathSync, existsSync } from 'fs';
import { IAirlyKey } from 'data-provider/airly/key-registry';
import { JobNames } from 'common/types';
// mitigation: dokku sets empty PORT env var for worker process
if (process.env?.PORT === '') {
delete process.env.PORT;
}
type ConfigSchema = {
env: string;
host: string;
port: number;
mongodb: string;
cache: {
ttl: {
measurements: number;
};
};
apiKeys: {
airly: IAirlyKey;
};
jobSchedule: {
[jobName in JobNames]: {
schedule: string;
healtcheck: string | null;
};
};
};
const config = convict<ConfigSchema>({
env: {
doc: 'The application environment.',
format: ['production', 'development'],
default: 'development',
env: 'NODE_ENV',
},
host: {
doc: 'The IP address to bind.',
format: 'ipaddress',
default: '127.0.0.1',
env: 'HOST',
},
port: {
doc: 'The port to bind.',
format: 'port',
default: 8080,
env: 'PORT',
},
mongodb: {
doc: 'MongoDB connection string',
format: '*',
default: 'mongodb://127.0.0.1:27017/airqmon',
env: 'MONGO_URL',
},
cache: {
ttl: {
measurements: {
doc: 'How often saved measurements should be refreshed on request (seconds)',
format: 'nat',
default: 900,
},
},
},
apiKeys: {
airly: {
key: {
format: String,
default: null,
env: 'AIRLY_API_KEY',
},
rateLimitDay: {
format: 'nat',
default: null,
env: 'AIRLY_RATE_LIMIT_DAY',
},
rateLimitMinute: {
format: 'nat',
default: null,
env: 'AIRLY_RATE_LIMIT_MINUTE',
},
},
},
jobSchedule: {
[JobNames.SYNC_STATIONS]: {
schedule: {
default: '0 0 * * *',
},
healtcheck: {
format: '*',
default: null,
},
},
[JobNames.CLEANUP_OLD_STATIONS]: {
schedule: {
default: '30 0 * * *',
},
healtcheck: {
format: '*',
default: null,
},
},
},
});
const envConfigPath = realpathSync(__dirname.concat(`/../../../config/${config.get('env')}.json`));
if (existsSync(envConfigPath)) {
config.loadFile(envConfigPath);
}
config.validate({ allowed: 'strict' });
export default config;