-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (33 loc) · 1.04 KB
/
server.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
var express = require('express'),
app = express(),
http = require('http').Server(app),
io = require('socket.io')(http);
app.use(express.static('public'));
/*io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
});*/
app.get('/', function (req, res) {
res.sendFile('index.html');
});
app.get('/refresh', function (req, res) {
var containersList = [];
var exec = require('child_process').exec;
exec('docker ps', function(error, stdout, stderr) {
var output = stdout.split('\n');
for(var index in output) {
var arr = output[index].split(/\s+/g);
//console.log(arr);
if(index != 0 && arr[0] != '') {
containersList.push({id: arr[0], image: arr[1], name: arr[arr.length-2], created: arr[3] + ' ' + arr[4] + ' ' + arr[5]});
}
}
io.emit('refresh', containersList);
res.send('0');
});
});
http.listen(8080, function () {
console.log('Server listening on *:8080');
});