refactor(server): resolve the data directory in one place

The data and uploads directories were derived independently in about ten
files, each counting `..` hops from its own `__dirname`, and the file
logger used `process.cwd()` instead. Moving a file or starting the server
from another directory quietly moved where secrets, backups or logs went,
and the backup code named `data/travel.db` directly, so with TREK_DB_FILE
set a backup archived and a restore replaced a file the connection never
opened.

`resolveDataPaths()` in app-config now anchors data/, uploads/, backups,
tmp, logs, the JWT secret and encryption key files and the database file
(TREK_DB_FILE when set, else data/travel.db) on the server package root.
Code that runs before the container calls it directly; Nest classes inject
the new `DataPathsService`. Every previous anchor uses it, and the resolved
paths are unchanged for the image and for `npm run dev`.
This commit is contained in:
Maurice
2026-10-08 15:03:23 +02:00
parent c84d0efb1a
commit 5c054863b9
21 changed files with 239 additions and 57 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import { readEnv } from '../../app-config';
import { resolveDataPaths } from '../../app-config/data-paths';
/**
* Filesystem layout for the plugin system (#plugins). Code and data are two
@@ -12,7 +13,7 @@ import { readEnv } from '../../app-config';
* so a Docker deployment can point them at dedicated volumes.
*/
const DATA_ROOT = path.resolve(__dirname, '../../../data');
const DATA_ROOT = resolveDataPaths().dataDir;
// Read lazily so a deployment (or a test) can point these at dedicated volumes
// via env without import-order surprises.