-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
44 lines (38 loc) · 1.11 KB
/
index.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
const Logger = require('./modules/logger');
const Config = require('./modules/config');
const Metrics = require('./modules/metrics');
const Timers = require('./modules/timers');
const Slack = require('./modules/slack');
const HealthCheck = require('./modules/healthCheck');
const Wrappers = require('./modules/wrappers');
const instances = {};
function getInstance(appName) {
const metrics = Metrics(appName);
const logger = Logger(metrics);
const config = Config();
const timers = Timers();
const slack = Slack(appName, config);
const healthCheck = HealthCheck(logger, config);
const wrappers = Wrappers(logger, timers);
return {
logger,
config,
metrics,
timers,
slack,
healthCheck,
wrappers,
};
}
function getSafeAppName(appName) {
return appName
.replace(/-/g, '_')
.replace(/[^a-z0-9_]/gi, '');
}
module.exports = (appName) => {
const safeAppName = getSafeAppName(appName);
if (!instances[safeAppName]) {
instances[safeAppName] = getInstance(safeAppName);
}
return instances[safeAppName];
};