-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathcustom_storage.js
53 lines (46 loc) · 1.27 KB
/
custom_storage.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
/* eslint-disable */
const { get } = require('http');
const { initialize } = require('../lib');
const { createClient } = require('redis');
class MyRedisStore {
async set(key, data) {
const client = createClient();
await client.connect();
await client.set(key, JSON.stringify(data));
}
async get(key) {
const client = createClient();
await client.connect();
const data = await client.get(key);
return JSON.parse(data);
}
}
const client = initialize({
appName: 'my-application',
url: 'http://localhost:3000/proxy/',
refreshInterval: 2000,
customHeaders: {
Authorization: 'bootstrap',
},
storageProvider: new MyRedisStore(),
});
client.on('error', () => console.log("\x1b[31m", 'Unable to fetch feature toggles', "\x1b[0m"));
client.on('warn', console.log);
client.on('synchronized', () => {
console.log('synchronized')
const enabled = client.isEnabled('BootstrapDemo');
console.log(
`BootstrapDemo: `,
`${enabled ? '\x1b[32m' : '\x1b[31m'}`,`${enabled}`,
'\x1b[0m',
);
});
client.on('ready', () => console.log('ready'));
setInterval(() => {
const enabled = client.isEnabled('BootstrapDemo');
console.log(
`BootstrapDemo: `,
`${enabled ? '\x1b[32m' : '\x1b[31m'}`,`${enabled}`,
'\x1b[0m',
);
}, 100)