Expose git commit hash to backend info api.

This commit is contained in:
softsimon
2020-05-27 15:18:04 +07:00
parent 4d4b6f4831
commit 8167debbe9
3 changed files with 35 additions and 19 deletions

View 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();