events {}
http {
    upstream dashboard {
        server infoscreen-dashboard:80;
    }
    upstream infoscreen_api {
        server infoscreen-api:8000;
    }
    server {
        listen 80;
        server_name _;
        # Allow larger uploads (match Flask MAX_CONTENT_LENGTH); adjust as needed
        client_max_body_size 1G;
        # Increase proxy timeouts for long uploads on slow connections
        proxy_read_timeout 3600s;
        proxy_send_timeout 3600s;

        # Leitet /api/ und /screenshots/ an den API-Server weiter
        location /api/ {
            proxy_pass http://infoscreen_api/api/;
        }
        location /screenshots/ {
            proxy_pass http://infoscreen_api/screenshots/;
        }
        # Public direct serving (optional)
        location /files/ {
            alias /opt/infoscreen/server/media/;
            sendfile on;
            tcp_nopush on;
            types {
                video/mp4 mp4;
                video/webm webm;
                video/ogg ogg;
            }
            add_header Accept-Ranges bytes;
            add_header Cache-Control "public, max-age=3600";
        }

        # Internal location for X-Accel-Redirect (protected)
        location /internal_media/ {
            internal;
            alias /opt/infoscreen/server/media/;
            sendfile on;
            tcp_nopush on;
            add_header Accept-Ranges bytes;
            add_header Cache-Control "private, max-age=0, s-maxage=3600";
        }
        # Alles andere geht ans Frontend
        location / {
            proxy_pass http://dashboard;
            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;
        }
    }
}
