server {
    listen 80;
    
    # Allow large uploads (100MB for batch uploads)
    client_max_body_size 100M;
    
    # ========================================
    # Backend API Routes (all under /api/)
    # ========================================
    # Basierend auf routeMappings.js:
    # - /api/upload, /api/download, /api/groups (Public API)
    # - /api/manage/* (Management Portal, Token-basiert)
    # - /api/admin/* (Admin/Moderation, Bearer Token)
    # - /api/system/migration/* (System API)
    
    location /api/ {
        proxy_pass http://backend-dev:5000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        
        # Large uploads für Batch-Upload
        client_max_body_size 100M;
    }
    
    # ========================================
    # Frontend Routes (React Dev Server)
    # ========================================
    
    # Moderation route proxy (session-protected in app layer)
    location /moderation {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    # WebSocket support for React Hot Reloading
    location /ws {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
    }

    # All other routes → React Dev Server (Client-side routing)
    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
