Fix config path resolution in PDF upload using getDataPath helper function

This commit is contained in:
Torsten Schulz (local)
2025-10-22 14:18:06 +02:00
parent e77963b13d
commit 05e25347ca
4 changed files with 113 additions and 100 deletions

View File

@@ -2,6 +2,19 @@ import multer from 'multer'
import fs from 'fs/promises'
import path from 'path'
// Handle both dev and production paths
const getDataPath = (filename) => {
const cwd = process.cwd()
// In production (.output/server), working dir is .output
if (cwd.endsWith('.output')) {
return path.join(cwd, '../server/data', filename)
}
// In development, working dir is project root
return path.join(cwd, 'server/data', filename)
}
// Multer-Konfiguration für PDF-Uploads
const storage = multer.diskStorage({
destination: (req, file, cb) => {
@@ -62,7 +75,7 @@ export default defineEventHandler(async (event) => {
`
// Config aktualisieren
const configPath = path.join(process.cwd(), 'server/data/config.json')
const configPath = getDataPath('config.json')
const configData = JSON.parse(await fs.readFile(configPath, 'utf-8'))
configData.seiten.satzung = {