Expose git commit hash to backend info api.
This commit is contained in:
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();
|
||||
Reference in New Issue
Block a user