mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
add debug-test app
This commit is contained in:
parent
e870c8457c
commit
167d1a8908
6
packages/unleash-demo-app/.eslintrc
Normal file
6
packages/unleash-demo-app/.eslintrc
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"finn",
|
||||||
|
"finn/node"
|
||||||
|
]
|
||||||
|
}
|
41
packages/unleash-demo-app/alot-of-clients.js
Normal file
41
packages/unleash-demo-app/alot-of-clients.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const unleash = require('unleash-client');
|
||||||
|
|
||||||
|
new Array(1000)
|
||||||
|
.join(',')
|
||||||
|
.split(',')
|
||||||
|
.forEach((v, index) => {
|
||||||
|
const instance = new unleash.Unleash({
|
||||||
|
appName: `demo-app-${index % 5}`,
|
||||||
|
instanceId: `index-${index}`,
|
||||||
|
url: 'http://10.200.229.88:4242/',
|
||||||
|
refreshIntervall: 4000,
|
||||||
|
metricsInterval: 10000,
|
||||||
|
strategies: [
|
||||||
|
new unleash.Strategy('extra', true),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
instance.on('ready', () => {
|
||||||
|
console.log('connected to unleash', index);
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
instance.isEnabled('toggle-1', null, Boolean(Math.round(Math.random() * 2)));
|
||||||
|
}, Math.round(Math.random() * 1000));
|
||||||
|
setInterval(() => {
|
||||||
|
instance.isEnabled('toggle-2', null, Boolean(Math.round(Math.random() * 2)));
|
||||||
|
}, 1500);
|
||||||
|
setInterval(() => {
|
||||||
|
instance.isEnabled('toggle-3', null, Boolean(Math.round(Math.random() * 2)));
|
||||||
|
}, 1300);
|
||||||
|
setInterval(() => {
|
||||||
|
instance.isEnabled('toggle-4', null, Boolean(Math.round(Math.random() * 2)));
|
||||||
|
}, 1300);
|
||||||
|
});
|
||||||
|
instance.on('error', (err) => {
|
||||||
|
console.error('index', index, err.message);
|
||||||
|
});
|
||||||
|
instance.on('warn', console.warn);
|
||||||
|
});
|
74
packages/unleash-demo-app/index.js
Normal file
74
packages/unleash-demo-app/index.js
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const express = require('express');
|
||||||
|
const unleash = require('unleash-client');
|
||||||
|
const chalk = require('chalk');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
const instance = unleash.initialize({
|
||||||
|
appName: 'demo-app',
|
||||||
|
url: 'http://localhost:4242/',
|
||||||
|
refreshIntervall: 4000,
|
||||||
|
metricsInterval: 10000,
|
||||||
|
strategies: [
|
||||||
|
new unleash.Strategy('extra', true),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
instance.on('ready', () => {
|
||||||
|
console.log('connected to unleash');
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
const result = unleash.isEnabled('add-feature-2', null, Boolean(Math.round(Math.random() * 2)));
|
||||||
|
console.log(chalk.yellow('add-feature-2'), chalk.blue(result.toString()));
|
||||||
|
}, 1000);
|
||||||
|
setInterval(() => {
|
||||||
|
const result = unleash.isEnabled('toggle-2', null, Boolean(Math.round(Math.random() * 2)));
|
||||||
|
console.log(chalk.green('toggle-2'), chalk.blue(result.toString()));
|
||||||
|
}, 1500);
|
||||||
|
setInterval(() => {
|
||||||
|
const result = unleash.isEnabled('toggle-3', null, Boolean(Math.round(Math.random() * 2)));
|
||||||
|
console.log(chalk.red('toggle-3'), chalk.blue(result.toString()));
|
||||||
|
}, 1500);
|
||||||
|
});
|
||||||
|
instance.on('error', (err) => {
|
||||||
|
console.error(err.message, err.stack);
|
||||||
|
});
|
||||||
|
instance.on('warn', console.warn);
|
||||||
|
|
||||||
|
|
||||||
|
function outputFeature (name, feature) {
|
||||||
|
if (feature.enabled === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return `<div>
|
||||||
|
<h3>${name}</h3>
|
||||||
|
<ul>${feature.strategies.map(strategy => `<li>${strategy.name}:<ul>${
|
||||||
|
Object
|
||||||
|
.keys(strategy.parameters)
|
||||||
|
.map((paramName) => `<li>${paramName}: ${strategy.parameters[paramName]}</li>`)
|
||||||
|
.join('')
|
||||||
|
}</ul></li>`)}</ul>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.get('/', (req, res) => {
|
||||||
|
const { data } = instance.repository.storage;
|
||||||
|
|
||||||
|
res.send(`<!DOCTYPE html>
|
||||||
|
<link rel="stylesheet" href="//static.finncdn.no/bb/css/spaden/5.2.1/spaden.min.css">
|
||||||
|
<meta http-equiv="refresh" content="5000">
|
||||||
|
<title>Demo example unleash-client usage</title>
|
||||||
|
|
||||||
|
${
|
||||||
|
Object.keys(data)
|
||||||
|
.map((key) => outputFeature(key, data[key]))
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('<hr />')
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(process.env.PORT || 1337);
|
21
packages/unleash-demo-app/package.json
Normal file
21
packages/unleash-demo-app/package.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "unleash-demo-app",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node ."
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.14.0",
|
||||||
|
"unleash-client": "^1.0.0-alpha.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/express": "^4.0.33",
|
||||||
|
"@types/node": "^6.0.45",
|
||||||
|
"chalk": "^1.1.3",
|
||||||
|
"unleash-api": "1.0.0-alpha.2"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
0
packages/unleash-demo-app/test.js
Normal file
0
packages/unleash-demo-app/test.js
Normal file
Loading…
Reference in New Issue
Block a user