Skip to content

Commit 1a7ae7c

Browse files
author
Cohen, Yohay
committed
Update configuration paths for runtime settings, migrating from project root to data/config directory for better Docker volume persistence. Adjust localization strings to reflect new file location and enhance backup service documentation for clarity.
1 parent d273843 commit 1a7ae7c

7 files changed

Lines changed: 44 additions & 11 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dist
44
**/dist
55
.env
66
runtime-settings.json
7+
data/config/runtime-settings.json
78
.git
89
.github
910
.vscode

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules
22
dist
33
.env
44
runtime-settings.json
5+
data/config/runtime-settings.json
56
.DS_Store
67
coverage
78
*.log

client/src/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@
11141114
},
11151115
"env": {
11161116
"title": "Environment Variables",
1117-
"subtitle": "Configure system-level settings stored in runtime-settings.json at the project root",
1117+
"subtitle": "Configure system-level settings stored in data/config/runtime-settings.json (next to your database; persists with the data folder / Docker volume)",
11181118
"profile_encryption_note": "Saved bank credentials are encrypted with your app password (set via the strip under the header). If you still have ENCRYPTION_KEY in runtime-settings.json from an older setup, unlock once after upgrade — profiles are re-encrypted automatically and you can remove that variable.",
11191119
"enter_value": "Enter {{key}}...",
11201120
"generate_random_key": "Generate random key",

client/src/locales/he.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@
11141114
},
11151115
"env": {
11161116
"title": "משתני סביבה",
1117-
"subtitle": "הגדרת משתני מערכת הנשמרים בקובץ runtime-settings.json בשורש הפרויקט",
1117+
"subtitle": "הגדרת משתני מערכת הנשמרים ב-data/config/runtime-settings.json (ליד מסד הנתונים; נשמר עם תיקיית הנתונים / נפח Docker)",
11181118
"profile_encryption_note": "פרטי התחברות לבנקים נשמרים מוצפנים עם סיסמת האפליקציה (מוגדרת בשורה מתחת לכותרת). אם עדיין קיים ENCRYPTION_KEY ב-runtime-settings.json מהגדרה ישנה, בטל נעילה פעם אחת אחרי העדכון — הפרופילים יוצפנו מחדש אוטומטית ואפשר להסיר את המשתנה.",
11191119
"enter_value": "הזן {{key}}...",
11201120
"generate_random_key": "צור מפתח אקראי",

client/vite.config.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ function normalizeBase(raw: string): string {
1111

1212
function readBackendPort(): string {
1313
if (process.env.PORT) return process.env.PORT
14-
try {
15-
const p = path.resolve(__dirname, '..', 'runtime-settings.json')
16-
const raw = fs.readFileSync(p, 'utf8')
17-
const j = JSON.parse(raw) as { PORT?: string }
18-
if (j.PORT) return String(j.PORT)
19-
} catch {
20-
// default matches server/src/index.ts
14+
const candidates = [
15+
path.resolve(__dirname, '..', 'data', 'config', 'runtime-settings.json'),
16+
path.resolve(__dirname, '..', 'runtime-settings.json')
17+
]
18+
for (const p of candidates) {
19+
try {
20+
const raw = fs.readFileSync(p, 'utf8')
21+
const j = JSON.parse(raw) as { PORT?: string }
22+
if (j.PORT) return String(j.PORT)
23+
} catch {
24+
// try next path
25+
}
2126
}
2227
return '3001'
2328
}

server/src/runtimeEnv.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const __dirname = path.dirname(__filename);
88
/** Repository root (parent of server/). */
99
export const PROJECT_ROOT = path.resolve(__dirname, '../..');
1010

11-
export const RUNTIME_SETTINGS_PATH = path.join(PROJECT_ROOT, 'runtime-settings.json');
11+
const DATA_DIR_RESOLVED = path.resolve(process.env.DATA_DIR || './data');
12+
/** Persisted env (API keys, OAuth, etc.) under the data directory so Docker volume mounts keep settings across restarts. */
13+
export const RUNTIME_SETTINGS_PATH = path.join(DATA_DIR_RESOLVED, 'config', 'runtime-settings.json');
14+
const LEGACY_RUNTIME_SETTINGS_PATH = path.join(PROJECT_ROOT, 'runtime-settings.json');
1215

1316
const LEGACY_ENV_PATH = path.join(PROJECT_ROOT, '.env');
1417

@@ -32,6 +35,28 @@ function parseEnvFile(content: string): Record<string, string> {
3235
return out;
3336
}
3437

38+
/**
39+
* One-time: copy project-root `runtime-settings.json` into `DATA_DIR/config/` (Docker-persisted path).
40+
*/
41+
function migrateLegacyRuntimeSettingsFile(): void {
42+
if (fs.existsSync(RUNTIME_SETTINGS_PATH)) {
43+
return;
44+
}
45+
if (!fs.existsSync(LEGACY_RUNTIME_SETTINGS_PATH)) {
46+
return;
47+
}
48+
fs.ensureDirSync(path.dirname(RUNTIME_SETTINGS_PATH));
49+
fs.copyFileSync(LEGACY_RUNTIME_SETTINGS_PATH, RUNTIME_SETTINGS_PATH);
50+
try {
51+
fs.unlinkSync(LEGACY_RUNTIME_SETTINGS_PATH);
52+
} catch {
53+
// keep legacy file if removal fails (e.g. permissions)
54+
}
55+
console.log(
56+
'[runtime] Migrated runtime-settings.json from project root to DATA_DIR/config/ (persists with your data volume)'
57+
);
58+
}
59+
3560
/**
3661
* If a legacy `.env` exists, merge it into `runtime-settings.json` and remove `.env`.
3762
*/
@@ -59,6 +84,7 @@ function migrateLegacyEnv(): void {
5984
* (OS / Docker env wins).
6085
*/
6186
export function applyRuntimeSettings(): void {
87+
migrateLegacyRuntimeSettingsFile();
6288
migrateLegacyEnv();
6389
if (!fs.existsSync(RUNTIME_SETTINGS_PATH)) {
6490
return;

server/src/services/backupService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const BACKUP_TARGETS = [
3232
/** Optional JSON files stored directly under DATA_DIR (not in a subfolder). */
3333
const DATA_DIR_ROOT_CONFIG_FILES = ['scheduler_config.json', 'notification_config.json'] as const;
3434

35-
/** Snapshot path for project-root runtime-settings.json (API keys, OAuth client id/secret, etc.). */
35+
/** Snapshot path label for runtime-settings (API keys, OAuth client id/secret, etc.); restored to DATA_DIR/config/runtime-settings.json. */
3636
const RUNTIME_SETTINGS_SNAPSHOT_PATH = 'root/runtime-settings.json';
3737

3838
interface BackupEntry {

0 commit comments

Comments
 (0)