-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
109 lines (92 loc) · 3.28 KB
/
app.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
console.log("server started");
var express = require('express');
var app = express();
var serv = require('http').Server(app);
var connectivity = require('connectivity');
var connectivity_status = "Not Available";
var availDisk, freeDisk, totalDiskm, cpu, ping;
var cpuStat = require('cpu-stat');
const disk = require('diskusage');
const os = require('os');
let path = os.platform() === 'win32' ? 'c:' : '/';
// set the view engine to ejs
app.set('view engine', 'ejs');
//route for dashboard
app.get('/',function(req, res) {
console.log("loading dashboard...");
res.sendFile(__dirname + '/client/index.html');
});
//route for wikipedia
app.get('/wiki',function(req, res) {
console.log("loading wikipedia...");
res.sendFile(__dirname + '/client/wiki.html');
});
//route for khan academy
app.get('/khan_academy',function(req, res) {
console.log("loading khan academy...");
res.sendFile(__dirname + '/client/khan_academy.html');
});
app.get('/duolingo',function(req, res) {
console.log("loading duolingo...");
res.sendFile(__dirname + '/client/duolingo.html');
});
app.get('/canvas',function(req, res) {
console.log("loading canvas...");
res.sendFile(__dirname + '/client/canvas.html');
});
//route for npm repo
app.get('/npm_repo',function(req, res) {
console.log("loading npm repo...");
res.sendFile(__dirname + '/client/npm_repo.html');
});
//route for vr app
app.get('/vr',function(req, res) {
console.log("loading VR resources...");
res.sendFile(__dirname + '/client/vr_app.html');
});
//route for vr app
app.get('/ar',function(req, res) {
console.log("loading AR resources...");
res.sendFile(__dirname + '/client/ar_app.html');
});
app.get('/dashboard', function(req,res) {
cpuStat.usagePercent(function(err, percent, seconds) {
if (err) {
return console.log(err);
}
//the percentage cpu usage over all cores
cpu = percent;
//the approximate number of seconds the sample was taken over
ping = seconds;
});
// get connectivity status
connectivity(function (online) {
if (online) {
connectivity_status = "Available"
}
});
// get disk usage
disk.check(path, function(err, info) {
if (err) {
console.log(err);
} else {
availDisk = Math.round(info.available/1000000000 * 100) / 100;
freeDisk = Math.round(info.free/1000000000 * 100) / 100;
totalDisk = Math.round(info.total/1000000000 * 100) / 100;
}
});
res.render(__dirname + '/views/index.ejs', {
connectivity_status: connectivity_status,
availDisk: availDisk,
disk: [freeDisk, totalDisk],
cpu: Math.round(cpu * 100) / 100,
deviceId: Math.random().toString(36).substr(2, 10),
ping: Math.round(ping * 10) / 10,
});
});
app.use('/client',express.static(__dirname + '/client'));//listens for when the client wants files.
app.use('/assets',express.static(__dirname + '/client/assets'));//listens for when the client wants files.
app.use('/css', express.static(__dirname + '/bootstrap/css/'));
app.use('/js', express.static(__dirname + '/bootstrap/js/'));
app.use('/scripts',express.static(__dirname + '/scripts'));//listens for files inside scripts
serv.listen(8000, '0.0.0.0');