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 e869c31c02
commit beaa95a733

View File

@@ -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 })