-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy.js
More file actions
23 lines (21 loc) · 771 Bytes
/
proxy.js
File metadata and controls
23 lines (21 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const http = require('http')
const handler = (req, res) => {
http.get('http://node:8732/chains/main/blocks/head/header', (subres) => {
let data = ''
subres.on('data', (chunk) => { data += chunk })
subres.on('end', () => {
console.log(data)
data = JSON.parse(data)
const block = data.level
const date = Math.round((new Date() - new Date(data.timestamp))/1000)
res.write('HELP Block\n')
res.write('TYPE block counter\n')
res.write(`block ${block}\n`)
res.write('HELP Time\n')
res.write('TYPE time gauge\n')
res.write(`time ${date}\n`)
res.end()
})
}).end()
}
http.createServer(handler).listen(8000)