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

2
.env
View File

@@ -38,7 +38,7 @@ LEGACY_MYSQL_PASSWORD=recipes_password_2024
# Security
JWT_SECRET=your_jwt_secret_here_change_in_production
CORS_ORIGIN=http://localhost:3000
CORS_ORIGIN=*
# Volume Paths
MYSQL_DATA_PATH=./docker-data/mysql

View File

@@ -1,27 +1,29 @@
# Development Environment Configuration
NODE_ENV=development
# Development Environment - Linux Server
# Generated on Mon Sep 22 05:45:27 PM UTC 2025
# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_NAME=rezepte_klaus
# Server Configuration
HOST_IP=192.168.178.94
DEVELOPMENT_MODE=true
# Database URL für Prisma
DATABASE_URL=mysql://root:@localhost:3306/rezepte_klaus
# Database Configuration (local development DB)
MYSQL_PASSWORD=dev_password_123
MYSQL_ROOT_PASSWORD=dev_root_password_123
# Backend Configuration
BACKEND_PORT=3001
# CORS Configuration for remote access
CORS_ORIGIN=*
# Upload Configuration
UPLOAD_DIR=./uploads
MAX_FILE_SIZE=10485760
ALLOWED_EXTENSIONS=jpg,jpeg,png,webp
# Development URLs:
# - Frontend: http://192.168.178.94:3000
# - Backend API: http://192.168.178.94:3001/api
# - phpMyAdmin: http://192.168.178.94:8080
# - MySQL: 192.168.178.94:3307
# Frontend Configuration (Vite Dev Server)
VITE_API_URL=http://localhost:3001
# Registry Configuration (for image pulls)
DOCKER_REGISTRY=docker.citysensor.de
# DOCKER_USERNAME=your_username
# DOCKER_PASSWORD=your_password
# Security
JWT_SECRET=dev_jwt_secret_change_in_production
CORS_ORIGIN=http://localhost:5173
# Development Notes:
# - Use this for testing Linux-specific behavior
# - Access from Mac via: http://192.168.178.94:3000
# - SSH tunnel for secure access: ssh -L 3000:192.168.178.94:3000 user@server

View File

@@ -0,0 +1,104 @@
services:
mysql:
image: mysql:8.0
container_name: rezepte-mysql-dev
restart: unless-stopped
environment:
- MYSQL_DATABASE=rezepte_klaus
- MYSQL_USER=rezepte
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
ports:
- "0.0.0.0:3307:3306"
volumes:
- mysql_dev_data:/var/lib/mysql
# Initialize with data
- ./Rezepte.sql:/docker-entrypoint-initdb.d/01-Rezepte.sql
- ./ingredients.sql:/docker-entrypoint-initdb.d/02-ingredients.sql
- ./Zubereitung.sql:/docker-entrypoint-initdb.d/03-Zubereitung.sql
- ./rezepte_bilder.sql:/docker-entrypoint-initdb.d/04-rezepte_bilder.sql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD}"]
interval: 30s
timeout: 10s
retries: 5
networks:
- rezepte-network
backend:
build:
context: ./nodejs-version/backend
dockerfile: Dockerfile
container_name: rezepte-backend-dev
restart: unless-stopped
environment:
- NODE_ENV=development
- DATABASE_URL=mysql://rezepte:${MYSQL_PASSWORD}@mysql:3306/rezepte_klaus
- CORS_ORIGIN=${CORS_ORIGIN:-*}
- PORT=3001
ports:
- "0.0.0.0:3001:3001"
volumes:
- uploads_dev_data:/app/uploads
# Mount existing uploads from host for development
- ./upload:/app/uploads:ro
# Development: Mount source code for hot reload
- ./nodejs-version/backend/src:/app/src:ro
- ./nodejs-version/backend/prisma:/app/prisma:ro
depends_on:
mysql:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3001/api/health"]
interval: 30s
timeout: 10s
retries: 3
networks:
- rezepte-network
frontend:
build:
context: ./nodejs-version/frontend
dockerfile: Dockerfile
container_name: rezepte-frontend-dev
restart: unless-stopped
ports:
- "0.0.0.0:3000:80"
depends_on:
- backend
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/"]
interval: 30s
timeout: 10s
retries: 3
networks:
- rezepte-network
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
container_name: rezepte-phpmyadmin-dev
restart: unless-stopped
environment:
- PMA_HOST=mysql
- PMA_PORT=3306
- PMA_USER=root
- PMA_PASSWORD=${MYSQL_ROOT_PASSWORD}
- UPLOAD_LIMIT=2G
- MEMORY_LIMIT=2G
ports:
- "0.0.0.0:8080:80"
depends_on:
mysql:
condition: service_healthy
networks:
- rezepte-network
volumes:
mysql_dev_data:
driver: local
uploads_dev_data:
driver: local
networks:
rezepte-network:
driver: bridge

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;
};

58
start-development.sh Executable file
View File

@@ -0,0 +1,58 @@
#!/bin/bash
set -e
echo "🚀 Starting Rezepte Klaus Development Environment on Linux"
echo "========================================================="
# Load environment variables
if [ -f .env.development ]; then
export $(cat .env.development | grep -v '^#' | xargs)
else
echo "❌ Error: .env.development file not found!"
echo "Please run setup-development.sh first."
exit 1
fi
echo "🔍 Server IP: $HOST_IP"
# Stop any existing containers
echo "🛑 Stopping existing containers..."
docker compose -f docker-compose.development.yml down
# Build and start services
echo "🏗️ Building and starting services..."
docker compose -f docker-compose.development.yml up -d --build
# Wait for services
echo "⏳ Waiting for services to start..."
sleep 30
# Check service health
echo "🔍 Checking service health..."
HEALTHY_SERVICES=$(docker compose -f docker-compose.development.yml ps --filter "status=running" | grep -c "Up" || true)
if [ "$HEALTHY_SERVICES" -ge 4 ]; then
echo "✅ Development environment started successfully!"
echo ""
echo "🌐 Access URLs:"
echo " Frontend: http://$HOST_IP:3000"
echo " Backend API: http://$HOST_IP:3001/api"
echo " phpMyAdmin: http://$HOST_IP:8080"
echo ""
echo "🔒 SSH Tunnel (for secure access from Mac):"
echo " ssh -L 3000:localhost:3000 -L 3001:localhost:3001 -L 8080:localhost:8080 user@$HOST_IP"
echo " Then access: http://localhost:3000"
echo ""
echo "📊 Service Status:"
docker compose -f docker-compose.development.yml ps
else
echo "❌ Some services failed to start. Check logs:"
docker compose -f docker-compose.development.yml logs --tail=20
fi
echo ""
echo "📋 Development Commands:"
echo " View logs: docker compose -f docker-compose.development.yml logs -f"
echo " Rebuild frontend: docker compose -f docker-compose.development.yml build frontend && docker compose -f docker-compose.development.yml restart frontend"
echo " Rebuild backend: docker compose -f docker-compose.development.yml build backend && docker compose -f docker-compose.development.yml restart backend"
echo " Stop: docker compose -f docker-compose.development.yml down"

1
upload Symbolic link
View File

@@ -0,0 +1 @@
uploads

1
uploads/upload Symbolic link
View File

@@ -0,0 +1 @@
upload