diff --git a/Dockerfile b/Dockerfile index e240d43..3a2d6eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -66,7 +66,7 @@ RUN if [ -f /server/.easter-eggs.json ]; then cp /server/.easter-eggs.json ./ser # Export /data/db.json do složky /data VOLUME ["/data"] -COPY /data/db.json /data/db.json +COPY /server/data/db.json /data/db.json EXPOSE 3000 diff --git a/server/src/storage/json.ts b/server/src/storage/json.ts index 23a7b88..30d386b 100644 --- a/server/src/storage/json.ts +++ b/server/src/storage/json.ts @@ -1,7 +1,17 @@ import JSONdb from 'simple-json-db'; import { StorageInterface } from "./StorageInterface"; +import * as fs from 'fs'; +import * as path from 'path'; -const db = new JSONdb('../data/db.json'); +const dbPath = path.resolve(__dirname, '../../data/db.json'); +const dbDir = path.dirname(dbPath); + +// Zajistěte, že adresář existuje +if (!fs.existsSync(dbDir)) { + fs.mkdirSync(dbDir, { recursive: true }); +} + +const db = new JSONdb(dbPath); /** * Implementace úložiště používající JSON soubor. */