CORS und uploads-Problem behoben

This commit is contained in:
2025-09-22 18:12:22 +00:00
parent 9b7bfcdab1
commit 3a55b95598
8 changed files with 198 additions and 25 deletions

View File

@@ -5,5 +5,8 @@ DATABASE_URL="mysql://rezepte_user:rezepte_pass@localhost:3307/rezepte_klaus"
PORT=3001
NODE_ENV=development
# CORS Configuration
CORS_ORIGIN=*
# Prisma
# DATABASE_URL="file:./dev.db"

View File

@@ -10,9 +10,13 @@ const prisma = new PrismaClient();
// Utility function to get correct uploads directory path
const getUploadsDir = (subPath?: string): string => {
const baseDir = process.env.NODE_ENV === 'production'
? path.join(process.cwd(), 'uploads')
: path.join(process.cwd(), '../../uploads');
// In Docker or when uploads directory exists in current directory, use local uploads
const localUploadsDir = path.join(process.cwd(), 'uploads');
const legacyUploadsDir = path.join(process.cwd(), '../../uploads');
const baseDir = fs.existsSync(localUploadsDir)
? localUploadsDir
: legacyUploadsDir;
return subPath ? path.join(baseDir, subPath) : baseDir;
};