From c6b66ad19c24dc49ebfed7fd6f10af34364901dc Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 14 Nov 2025 22:26:08 +0100 Subject: [PATCH] Refactor CSV save functionality in CMS API to handle file paths dynamically for both development and production environments. Ensure correct directory structure is maintained for data storage. --- server/api/cms/save-csv.post.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server/api/cms/save-csv.post.js b/server/api/cms/save-csv.post.js index ed3aff3..6ae774e 100644 --- a/server/api/cms/save-csv.post.js +++ b/server/api/cms/save-csv.post.js @@ -45,9 +45,19 @@ export default defineEventHandler(async (event) => { }) } - // Pfad zur Datenverzeichnis - const dataDir = path.join(process.cwd(), 'public', 'data') - const filePath = path.join(dataDir, filename) + // Handle both dev and production paths + const cwd = process.cwd() + let filePath + + // In production (.output/server), working dir is .output + if (cwd.endsWith('.output')) { + filePath = path.join(cwd, '../public/data', filename) + } else { + // In development, working dir is project root + filePath = path.join(cwd, 'public/data', filename) + } + + const dataDir = path.dirname(filePath) // Sicherstellen, dass das Verzeichnis existiert await fs.mkdir(dataDir, { recursive: true })