forked from splitio/split-evaluator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdk.js
56 lines (49 loc) · 1.29 KB
/
sdk.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
//
// SDK initialization and factory instanciation.
//
'use strict';
const SplitFactory = require('@splitsoftware/splitio');
const config = require('config');
const merge = require('lodash/merge');
// Support for API KEY override
const envSettings = config.get('sdk');
let settings = envSettings;
if (process.env.SPLITIO_API_KEY) {
settings = merge({}, settings, {
core: {
authorizationKey: process.env.SPLITIO_API_KEY
}
});
} else {
console.log('No API Key was provided.');
throw new Error('API Key cannot be empty or null.');
}
//SDK URL can be set by env for debug
if (process.env.SDK_URL) {
console.log('Setting custom SDK API url.');
settings = merge({}, settings, {
urls: {
sdk: process.env.SDK_URL
}
});
}
//EVENTS URL can be set by env for debug
if (process.env.EVENTS_URL) {
console.log('Setting custom SDK Events url.');
settings = merge({}, settings, {
urls: {
events: process.env.EVENTS_URL
}
});
}
if (process.env.SPLITIO_SCHEDULER) {
try {
console.log('Setting custom SDK scheduler timers.');
settings = merge({}, settings, {
scheduler: JSON.parse(process.env.SPLITIO_SCHEDULER)
});
} catch(e) {
console.log('There was an error parsing the custom scheduler');
}
}
module.exports = SplitFactory(settings);