-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
131 lines (113 loc) · 3.59 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const http = require("http");
const io = require('socket.io')();
let pods = [];
let services = [];
let deployments = [];
const hostname = process.env.OPENSHIFT_BACKEND_HOST || process.env.BACKEND_HOST || 'localhost';
const port = process.env.SERVER_PORT || 8000;
const podOptions = {
host: hostname,
path: "/getPods",
method: "GET"
};
const serviceOptions = {
host: hostname,
path: "/getServices",
method: "GET"
};
const deploymentOptions = {
host: hostname,
path: "/getDeployments",
method: "GET"
};
io.on('connection', (client) => {
// Pods
var req1 = http.request(podOptions, function (res) {
var responseString = "";
res.on("data", function (data) {
responseString += data;
});
res.on("end", function () {
pods = JSON.parse(responseString);
console.log(pods);
});
});
req1.end();
// Services
var req2 = http.request(serviceOptions, function (res) {
var responseString = "";
res.on("data", function (data) {
responseString += data;
});
res.on("end", function () {
services = JSON.parse(responseString);
console.log(services);
});
});
req2.end();
// Deployments
var req3 = http.request(deploymentOptions, function (res) {
var responseString = "";
res.on("data", function (data) {
responseString += data;
});
res.on("end", function () {
deployments = JSON.parse(responseString);
console.log(deployments);
});
});
req3.end();
client.on('subscribeToPods', (interval) => {
console.log('client is subscribing to pods with interval ', interval);
setInterval(() => {
var req = http.request(podOptions, function (res) {
var responseString = "";
res.on("data", function (data) {
responseString += data;
});
res.on("end", function () {
console.log(pods);
pods = JSON.parse(responseString);
});
});
req.end();
client.emit('pods', pods);
}, interval);
});
client.on('subscribeToServices', (interval) => {
console.log('client is subscribing to services with interval ', interval);
setInterval(() => {
var req = http.request(serviceOptions, function (res) {
var responseString = "";
res.on("data", function (data) {
responseString += data;
});
res.on("end", function () {
console.log(services);
services = JSON.parse(responseString);
});
});
req.end();
client.emit('services', services);
}, interval);
});
client.on('subscribeToDeployments', (interval) => {
console.log('client is subscribing to deployments with interval ', interval);
setInterval(() => {
var req = http.request(deploymentOptions, function (res) {
var responseString = "";
res.on("data", function (data) {
responseString += data;
});
res.on("end", function () {
console.log(deployments);
deployments = JSON.parse(responseString);
});
});
req.end();
client.emit('deployments', deployments);
}, interval);
});
});
io.listen(port);
console.log('listening on port ', port);