42 lines
860 B
JavaScript
42 lines
860 B
JavaScript
|
const express = require('express')
|
||
|
const cprog = require('child_process')
|
||
|
const path = require('path')
|
||
|
|
||
|
const app = express()
|
||
|
const port = process.env.PORT || 8432
|
||
|
|
||
|
/* Information segment */
|
||
|
|
||
|
let info = {}
|
||
|
let infoTimer
|
||
|
|
||
|
async function requestInfo () {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
let proc = cprog.exec('node ' + path.join(__dirname, 'system.js'), (err, stdout) => {
|
||
|
if (err) return reject(err)
|
||
|
resolve(JSON.parse(stdout))
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
|
||
|
function update () {
|
||
|
requestInfo().then((newInfo) => {
|
||
|
info = newInfo
|
||
|
}).catch(e => console.error(e))
|
||
|
}
|
||
|
|
||
|
infoTimer = setInterval(update, 8000)
|
||
|
update()
|
||
|
|
||
|
/* Web server segment */
|
||
|
|
||
|
app.use('/status', function (req, res) {
|
||
|
res.jsonp(info)
|
||
|
})
|
||
|
|
||
|
app.use('/', express.static(path.join(__dirname, 'public')))
|
||
|
|
||
|
app.listen(port, function (argument) {
|
||
|
console.log('Listening on', port)
|
||
|
})
|