From 89dec1c19490042fdb9908390ae6252c3a612d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20H=C3=A1jek?= Date: Sun, 2 Feb 2025 19:46:20 +0100 Subject: [PATCH] =?UTF-8?q?Zalo=C5=BEen=C3=AD=20slo=C5=BEky=20server/data,?= =?UTF-8?q?=20pokud=20neexistuje,=20do=20kter=C3=A9=20je=20vytvo=C5=99en?= =?UTF-8?q?=20soubor=20db.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- server/src/storage/json.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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. */