mirror of
https://github.com/Xahau/Validation-Ledger-Tx-Store-to-xPOP.git
synced 2025-11-19 19:25:52 +00:00
Add health + stats endpoint
This commit is contained in:
@@ -5,6 +5,12 @@ import expressWs from 'express-ws'
|
||||
import autoindex from 'express-autoindex/dist/index.cjs.js'
|
||||
import 'dotenv/config'
|
||||
|
||||
import { lastLedger } from '../lib/onLedger.mjs'
|
||||
import { txCount } from '../lib/onTransaction.mjs'
|
||||
|
||||
const startDate = new Date()
|
||||
let lastLedgerTx
|
||||
|
||||
let wss // WebSocket Server
|
||||
|
||||
if (!wss) {
|
||||
@@ -27,6 +33,15 @@ if (!wss) {
|
||||
|
||||
app.use('/', express.static('./store/'))
|
||||
|
||||
app.use('/health', (req, res) => {
|
||||
res.json({
|
||||
uptime: new Date() - startDate,
|
||||
lastLedger: lastLedger ?? null,
|
||||
lastLedgerTx: lastLedgerTx ?? null,
|
||||
txCount: txCount ?? null,
|
||||
})
|
||||
})
|
||||
|
||||
app.use('/:networkId([0-9]{1,})', (req, res, next) => {
|
||||
return autoindex('./store/' + req.params.networkId + '/', { json: /application\/json/.test(req.get('accept')) })(req, res, next)
|
||||
})
|
||||
@@ -78,6 +93,8 @@ const emit = _data => {
|
||||
data.xpop.blob = undefined
|
||||
}
|
||||
|
||||
lastLedgerTx = data.origin.ledgerIndex
|
||||
|
||||
if (account === '' || data.account === account) {
|
||||
client.send(JSON.stringify(data), { binary: false })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user