Skip to content

Commit 2d3e4b2

Browse files
committed
feat: failing endpoint indicator demo wip
1 parent 7f5b586 commit 2d3e4b2

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"start": "node src/main.js"
66
},
77
"dependencies": {
8-
"sourceplusplus": "^0.0.8"
8+
"sourceplusplus": "^0.0.8",
9+
"express": "4.18.1"
910
}
1011
}

src/indicator/FailingEndpoint.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const express = require('express');
2+
const router = express.Router();
3+
4+
router.get('/fail-100-percent', (req, res) => {
5+
res.sendStatus(500);
6+
});
7+
8+
router.get('/fail-75-percent', (req, res) => {
9+
if (Math.random() < 0.25) {
10+
res.sendStatus(200);
11+
} else {
12+
res.sendStatus(500);
13+
}
14+
});
15+
16+
router.get('/fail-50-percent', (req, res) => {
17+
if (Math.random() > 0.5) {
18+
res.sendStatus(500);
19+
} else {
20+
res.sendStatus(200);
21+
}
22+
});
23+
24+
module.exports = router;

src/main.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,23 @@ function executeDemos() {
88
}
99

1010
setInterval(executeDemos, 1000);
11+
12+
function startIndicators() {
13+
const express = require('express');
14+
15+
const app = express();
16+
const failingEndpoint = require('./indicator/FailingEndpoint');
17+
app.use('/indicator', failingEndpoint);
18+
app.listen(3000);
19+
}
20+
21+
startIndicators();
22+
23+
function executeIndicators() {
24+
const axios = require('axios');
25+
axios.get('http://localhost:3000/indicator/fail-100-percent').catch(() => {});
26+
axios.get('http://localhost:3000/indicator/fail-75-percent').catch(() => {});
27+
axios.get('http://localhost:3000/indicator/fail-50-percent').catch(() => {});
28+
}
29+
30+
setInterval(executeIndicators, 1000);

0 commit comments

Comments
 (0)