mirror of
https://github.com/Xahau/Validation-Ledger-Tx-Store-to-xPOP.git
synced 2025-12-06 17:27:57 +00:00
Add version to health & homempage response
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { WebSocket } from 'ws'
|
import { WebSocket } from 'ws'
|
||||||
|
import { readFile } from 'fs'
|
||||||
import morgan from 'morgan'
|
import morgan from 'morgan'
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import expressWs from 'express-ws'
|
import expressWs from 'express-ws'
|
||||||
@@ -19,6 +20,23 @@ const telemetry = {
|
|||||||
sent: false,
|
sent: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const version = await new Promise(resolve => {
|
||||||
|
readFile(new URL('../package.json', import.meta.url).pathname, (err, data) => {
|
||||||
|
if (!err) {
|
||||||
|
try {
|
||||||
|
const pjson = JSON.parse(data)
|
||||||
|
return resolve(pjson?.version)
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve(null)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('Running backend version', version || '<< UNKNOWN >>')
|
||||||
|
|
||||||
const sendTelemetry = async () => {
|
const sendTelemetry = async () => {
|
||||||
if (process.env?.TELEMETRY === 'YES') {
|
if (process.env?.TELEMETRY === 'YES') {
|
||||||
try {
|
try {
|
||||||
@@ -98,11 +116,13 @@ if (!wss) {
|
|||||||
unlkey: process.env?.UNLKEY ?? null,
|
unlkey: process.env?.UNLKEY ?? null,
|
||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
|
version,
|
||||||
networkid: process.env?.NETWORKID ?? null,
|
networkid: process.env?.NETWORKID ?? null,
|
||||||
urlprefix: process.env?.URL_PREFIX ?? null,
|
urlprefix: process.env?.URL_PREFIX ?? null,
|
||||||
requiredTxFields: typeof process.env?.FIELDSREQUIRED === 'string' ? process.env.FIELDSREQUIRED.split(',') : null,
|
requiredTxFields: typeof process.env?.FIELDSREQUIRED === 'string' ? process.env.FIELDSREQUIRED.split(',') : null,
|
||||||
},
|
},
|
||||||
stats: {
|
stats: {
|
||||||
|
uptime: new Date() - startDate,
|
||||||
lastLedger: lastLedger ?? null,
|
lastLedger: lastLedger ?? null,
|
||||||
lastWsPushedLedger: lastWsPushedLedger ?? null,
|
lastWsPushedLedger: lastWsPushedLedger ?? null,
|
||||||
txCount: txCount ?? null,
|
txCount: txCount ?? null,
|
||||||
@@ -118,6 +138,7 @@ if (!wss) {
|
|||||||
app.use('/health', (req, res) => {
|
app.use('/health', (req, res) => {
|
||||||
res.setHeader('content-type', 'application/json')
|
res.setHeader('content-type', 'application/json')
|
||||||
res.json({
|
res.json({
|
||||||
|
version,
|
||||||
uptime: new Date() - startDate,
|
uptime: new Date() - startDate,
|
||||||
lastLedger: lastLedger ?? null,
|
lastLedger: lastLedger ?? null,
|
||||||
lastWsPushedLedger: lastWsPushedLedger ?? null,
|
lastWsPushedLedger: lastWsPushedLedger ?? null,
|
||||||
|
|||||||
Reference in New Issue
Block a user