mirror of
https://github.com/mempool/mempool.git
synced 2025-02-27 08:10:05 +01:00
Extract `fetch-version.ts` which is called at build time to create file `dist/api/version.json`. This file is read by `backend-info.ts` at runtime. This also fixes handing over the Git commit hash to the backend app in the Docker backend image, which was broken as of 2022-07-12. (Reason: The commit hash was previously required at runtime, but was only provided at build time.)
38 lines
975 B
TypeScript
38 lines
975 B
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import os from 'os';
|
|
import { IBackendInfo } from '../mempool.interfaces';
|
|
|
|
class BackendInfo {
|
|
private backendInfo: IBackendInfo;
|
|
|
|
constructor() {
|
|
// This file is created by ./fetch-version.ts during building
|
|
const versionFile = path.join(__dirname, 'version.json')
|
|
var versionInfo;
|
|
if (fs.existsSync(versionFile)) {
|
|
versionInfo = JSON.parse(fs.readFileSync(versionFile).toString());
|
|
} else {
|
|
// Use dummy values if `versionFile` doesn't exist (e.g., during testing)
|
|
versionInfo = {
|
|
version: '?',
|
|
gitCommit: '?'
|
|
};
|
|
}
|
|
this.backendInfo = {
|
|
hostname: os.hostname(),
|
|
version: versionInfo.version,
|
|
gitCommit: versionInfo.gitCommit
|
|
};
|
|
}
|
|
|
|
public getBackendInfo(): IBackendInfo {
|
|
return this.backendInfo;
|
|
}
|
|
|
|
public getShortCommitHash() {
|
|
return this.backendInfo.gitCommit.slice(0, 7);
|
|
}
|
|
}
|
|
|
|
export default new BackendInfo();
|