🐛 Fix server version on docker (#5093)

* fix server version on docker

* bit more safety

* fix lint

* release notes

* more error handling
This commit is contained in:
Michael Clark
2025-06-04 17:31:37 +00:00
committed by GitHub
parent bfb2d61286
commit 7441b5fa92
2 changed files with 41 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
import { createRequire } from 'module';
import fs, { readFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import bodyParser from 'body-parser';
import cors from 'cors';
@@ -68,17 +69,42 @@ app.get('/mode', (req, res) => {
});
app.get('/info', (_req, res) => {
const require = createRequire(import.meta.url);
const packageJsonPath = require.resolve(
'@actual-app/sync-server/package.json',
);
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
function findPackageJson(startDir: string) {
// find the nearest package.json file while traversing up the directory tree
let currentPath = startDir;
let directoriesSearched = 0;
const pathRoot = resolve(currentPath, '/');
try {
while (currentPath !== pathRoot && directoriesSearched < 5) {
const packageJsonPath = resolve(currentPath, 'package.json');
if (fs.existsSync(packageJsonPath)) {
const packageJson = JSON.parse(
readFileSync(packageJsonPath, 'utf-8'),
);
if (packageJson.name === '@actual-app/sync-server') {
return packageJson;
}
}
currentPath = resolve(join(currentPath, '..')); // Move up one directory
directoriesSearched++;
}
} catch (error) {
console.error('Error while searching for package.json:', error);
}
return null;
}
const dirname = resolve(fileURLToPath(import.meta.url), '../');
const packageJson = findPackageJson(dirname);
res.status(200).json({
build: {
name: packageJson.name,
description: packageJson.description,
version: packageJson.version,
name: packageJson?.name,
description: packageJson?.description,
version: packageJson?.version,
},
});
});

View File

@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MikesGlitch]
---
Fix server version display on docker images