mempool/backend/src/api/backend-info.ts

35 lines
718 B
TypeScript
Raw Normal View History

import * as fs from 'fs';
import * as os from 'os';
import logger from '../logger';
class BackendInfo {
gitCommitHash = '';
hostname = '';
constructor() {
this.setLatestCommitHash();
this.hostname = os.hostname();
}
public getBackendInfo() {
return {
'hostname': this.hostname,
'git-commit': this.gitCommitHash,
};
}
public getShortCommitHash() {
return this.gitCommitHash.slice(0, 7);
}
private setLatestCommitHash(): void {
try {
this.gitCommitHash = fs.readFileSync('../.git/refs/heads/master').toString().trim();
} catch (e) {
2020-10-28 05:00:48 +01:00
logger.err('Could not load git commit info: ' + e.message || e);
}
}
}
export default new BackendInfo();