mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 12:43:09 -05:00
🐛 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:
@@ -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,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
6
upcoming-release-notes/5093.md
Normal file
6
upcoming-release-notes/5093.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [MikesGlitch]
|
||||
---
|
||||
|
||||
Fix server version display on docker images
|
||||
Reference in New Issue
Block a user