-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
78 lines (66 loc) · 2.17 KB
/
example.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const http = require('http');
const express = require('express');
const Indago = require('./index.js');
const app = express();
const analyticsTracker = new Indago.Tracker({
template: {
// Custom analytics properties
imageFolderSize: 0 // Example property
},
savePath: __dirname + '/analytics.json', // Path to save analytics data
clearIPsInterval: 10 * 60000,
realm: 'example analytics', // This string is displayed next to the login prompt on some browsers.
authentication: { // Defaults to false for no dashboard route authentication
// Choose only one method of dashboard authentication:
// 1. Username and Password
username: 'root',
password: 'securepassword123',
// 2. Base64 Authentication Header Code
// base64: 'cm9vdDpzZWN1cmVwYXNzd29yZDMxMg==',
// // atob('cm9vdDpzZWN1cmVwYXNzd29yZDMxMg==') === 'root:securepassword312'
// 3. SHA256 Hash of Base64 Authentication Header Code
// hexHash: '68832558e77a2f66eb7703a4813b284fc49e086db75f232029ab269d0a494f55'
// // SHA256 Hash of 'cm9vdDpzZWN1cmVwYXNzd29yZDMxMg=='
},
// Called every 10 seconds
onTick: async () => {
if(Indago.Ticker('Update Image Folder Size', 10000)) { // Updates the image folder size every 5 minutes
analyticsTracker.update({
imageFolderSize: await getImageFolderSize()
});
}
},
// Called when a request is made to the debug route
onDebugRequest: (req, res) => {},
});
app.use('/_analytics', analyticsTracker.analyticsMW());
app.get('/', analyticsTracker.trackerMW(), (req, res) => {
res.send("Hello!");
});
function doSetupTask() {
return new Promise(resolve => {
console.log("Setting up server...");
setTimeout(resolve, 1000);
});
}
function setupDatabaseOrSomethingSimilar() {
return new Promise(resolve => {
console.log("Setting up database...");
setTimeout(resolve, 1000);
});
}
function getImageFolderSize() {
return new Promise(resolve => {
console.log("Getting folder size...");
setTimeout(() => {
resolve(Math.floor(Math.random() * 1000));
}, 1000);
});
};
doSetupTask().then(async () => {
await setupDatabaseOrSomethingSimilar();
analyticsTracker.init();
app.listen(3000, () => {
console.log('listening on *:3000');
});
}).catch(console.error);