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');
|
const config = require('../../mempool-config.json');
|
||||||
|
|
||||||
import * as WebSocket from 'ws';
|
import * as WebSocket from 'ws';
|
||||||
import * as fs from 'fs';
|
|
||||||
import { Block, TransactionExtended, Statistic, WebsocketResponse } from '../interfaces';
|
import { Block, TransactionExtended, Statistic, WebsocketResponse } from '../interfaces';
|
||||||
import blocks from './blocks';
|
import blocks from './blocks';
|
||||||
import memPool from './mempool';
|
import memPool from './mempool';
|
||||||
|
import backendInfo from './backend-info';
|
||||||
import mempoolBlocks from './mempool-blocks';
|
import mempoolBlocks from './mempool-blocks';
|
||||||
import fiatConversion from './fiat-conversion';
|
import fiatConversion from './fiat-conversion';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
|
|
||||||
class WebsocketHandler {
|
class WebsocketHandler {
|
||||||
private wss: WebSocket.Server | undefined;
|
private wss: WebSocket.Server | undefined;
|
||||||
private latestGitCommitHash = '';
|
|
||||||
private nativeAssetId = '6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d';
|
private nativeAssetId = '6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d';
|
||||||
|
|
||||||
constructor() {
|
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.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setWebsocketServer(wss: WebSocket.Server) {
|
setWebsocketServer(wss: WebSocket.Server) {
|
||||||
this.wss = wss;
|
this.wss = wss;
|
||||||
@ -93,8 +82,8 @@ class WebsocketHandler {
|
|||||||
'blocks': _blocks.slice(Math.max(_blocks.length - config.INITIAL_BLOCK_AMOUNT, 0)),
|
'blocks': _blocks.slice(Math.max(_blocks.length - config.INITIAL_BLOCK_AMOUNT, 0)),
|
||||||
'conversions': fiatConversion.getTickers()['BTCUSD'],
|
'conversions': fiatConversion.getTickers()['BTCUSD'],
|
||||||
'mempool-blocks': mempoolBlocks.getMempoolBlocks(),
|
'mempool-blocks': mempoolBlocks.getMempoolBlocks(),
|
||||||
'git-commit': this.latestGitCommitHash,
|
'git-commit': backendInfo.gitCommitHash,
|
||||||
'hostname': os.hostname(),
|
'hostname': backendInfo.hostname,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import statistics from './api/statistics';
|
import statistics from './api/statistics';
|
||||||
import feeApi from './api/fee-api';
|
import feeApi from './api/fee-api';
|
||||||
|
import backendInfo from './api/backend-info';
|
||||||
import mempoolBlocks from './api/mempool-blocks';
|
import mempoolBlocks from './api/mempool-blocks';
|
||||||
import mempool from './api/mempool';
|
import mempool from './api/mempool';
|
||||||
import * as os from 'os';
|
|
||||||
|
|
||||||
class Routes {
|
class Routes {
|
||||||
private cache = {};
|
private cache = {};
|
||||||
@ -76,9 +76,7 @@ class Routes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getBackendInfo(req, res) {
|
public getBackendInfo(req, res) {
|
||||||
res.send({
|
res.send(backendInfo.getBackendInfo());
|
||||||
'hostname': os.hostname(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user