mirror of
https://github.com/mempool/mempool.git
synced 2025-01-17 18:52:34 +01:00
Expose git commit hash to backend info api.
This commit is contained in:
parent
4d4b6f4831
commit
8167debbe9
29
backend/src/api/backend-info.ts
Normal file
29
backend/src/api/backend-info.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
|
||||
class BackendInfo {
|
||||
gitCommitHash = '';
|
||||
hostname = '';
|
||||
|
||||
constructor() {
|
||||
this.setLatestCommitHash();
|
||||
this.hostname = os.hostname();
|
||||
}
|
||||
|
||||
public getBackendInfo() {
|
||||
return {
|
||||
'hostname': this.hostname,
|
||||
'git-commit': this.gitCommitHash,
|
||||
};
|
||||
}
|
||||
|
||||
private setLatestCommitHash(): void {
|
||||
try {
|
||||
this.gitCommitHash = fs.readFileSync('../.git/refs/heads/master').toString().trim();
|
||||
} catch (e) {
|
||||
console.log('Could not load git commit info, skipping.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new BackendInfo();
|
@ -1,30 +1,19 @@
|
||||
const config = require('../../mempool-config.json');
|
||||
|
||||
import * as WebSocket from 'ws';
|
||||
import * as fs from 'fs';
|
||||
import { Block, TransactionExtended, Statistic, WebsocketResponse } from '../interfaces';
|
||||
import blocks from './blocks';
|
||||
import memPool from './mempool';
|
||||
import backendInfo from './backend-info';
|
||||
import mempoolBlocks from './mempool-blocks';
|
||||
import fiatConversion from './fiat-conversion';
|
||||
import * as os from 'os';
|
||||
|
||||
class WebsocketHandler {
|
||||
private wss: WebSocket.Server | undefined;
|
||||
private latestGitCommitHash = '';
|
||||
private nativeAssetId = '6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d';
|
||||
|
||||
constructor() {
|
||||
this.setLatestGitCommit();
|
||||
}
|
||||
|
||||
setLatestGitCommit() {
|
||||
try {
|
||||
this.latestGitCommitHash = fs.readFileSync('../.git/refs/heads/master').toString().trim();
|
||||
} catch (e) {
|
||||
console.log('Could not load git commit info, skipping.');
|
||||
}
|
||||
}
|
||||
constructor() { }
|
||||
|
||||
setWebsocketServer(wss: WebSocket.Server) {
|
||||
this.wss = wss;
|
||||
@ -93,8 +82,8 @@ class WebsocketHandler {
|
||||
'blocks': _blocks.slice(Math.max(_blocks.length - config.INITIAL_BLOCK_AMOUNT, 0)),
|
||||
'conversions': fiatConversion.getTickers()['BTCUSD'],
|
||||
'mempool-blocks': mempoolBlocks.getMempoolBlocks(),
|
||||
'git-commit': this.latestGitCommitHash,
|
||||
'hostname': os.hostname(),
|
||||
'git-commit': backendInfo.gitCommitHash,
|
||||
'hostname': backendInfo.hostname,
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import statistics from './api/statistics';
|
||||
import feeApi from './api/fee-api';
|
||||
import backendInfo from './api/backend-info';
|
||||
import mempoolBlocks from './api/mempool-blocks';
|
||||
import mempool from './api/mempool';
|
||||
import * as os from 'os';
|
||||
|
||||
class Routes {
|
||||
private cache = {};
|
||||
@ -76,9 +76,7 @@ class Routes {
|
||||
}
|
||||
|
||||
public getBackendInfo(req, res) {
|
||||
res.send({
|
||||
'hostname': os.hostname(),
|
||||
});
|
||||
res.send(backendInfo.getBackendInfo());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user