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:
@@ -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 })
|
||||||
|
|||||||
Reference in New Issue
Block a user