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.

This commit is contained in:
Torsten Schulz (local)
2025-11-14 22:26:08 +01:00
parent 3d6646cf31
commit c6b66ad19c

View File

@@ -45,9 +45,19 @@ export default defineEventHandler(async (event) => {
}) })
} }
// Pfad zur Datenverzeichnis // Handle both dev and production paths
const dataDir = path.join(process.cwd(), 'public', 'data') const cwd = process.cwd()
const filePath = path.join(dataDir, filename) 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 // Sicherstellen, dass das Verzeichnis existiert
await fs.mkdir(dataDir, { recursive: true }) await fs.mkdir(dataDir, { recursive: true })