Založení složky server/data, pokud neexistuje, do které je vytvořen soubor db.json

This commit is contained in:
Michal Hájek 2025-02-02 19:46:20 +01:00
parent f3af64923c
commit 89dec1c194
2 changed files with 12 additions and 2 deletions

View File

@ -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 # Export /data/db.json do složky /data
VOLUME ["/data"] VOLUME ["/data"]
COPY /data/db.json /data/db.json COPY /server/data/db.json /data/db.json
EXPOSE 3000 EXPOSE 3000

View File

@ -1,7 +1,17 @@
import JSONdb from 'simple-json-db'; import JSONdb from 'simple-json-db';
import { StorageInterface } from "./StorageInterface"; 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. * Implementace úložiště používající JSON soubor.
*/ */