-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxyz.monitor.basic.bootstrap.js
More file actions
46 lines (40 loc) · 1.22 KB
/
Copy pathxyz.monitor.basic.bootstrap.js
File metadata and controls
46 lines (40 loc) · 1.22 KB
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
let express = require('express')
let monitorCallReceive = require('./middleware/xyz.monitor.call.receive.middleware')
let monitorCallSend = require('./middleware/xyz.monitor.call.send.middleware')
let load = { snd: 0, rcv: 0}
let logger
function _basicMonitor (xyz, port = 5000) {
/*
Initialize a simple express server
*/
logger = xyz.logger
var app = express()
app.use(express.static(__dirname + '/lib'))
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html')
})
app.get('/all', function (req, res) {
res.json({load: load, inspectJSON: xyz.inspectJSON(), inspect: xyz.inspect()})
})
let listener = app.listen(port, function () {
logger.info(`monitor server started at port ${listener.address().port}`)
})
/*
Register required middlewares
*/
xyz.middlewares().transport.server('CALL')(xyz.id().port).register(0,
monitorCallReceive)
xyz.middlewares().transport.client('CALL').register(0,
monitorCallSend)
}
module.exports = {
// will be used by the user of this bootstrap function
bootstrap: _basicMonitor,
// will be used by the two middlewares inserted
setSendLoad: (aLoad) => {
load.snd = aLoad
},
setRcvLoad: (aLoad) => {
load.rcv = aLoad
}
}