# =============================================================
# video-accessibility — Apache config fragment
# optical-dev.oliver.solutions
#
# This file is auto-overwritten by scripts/deploy-dev.sh on
# every deploy (to pick up PORT / WEBROOT changes).
# Do NOT add custom edits here — put them in deploy-dev.sh.
#
# Required modules:
#   sudo a2enmod proxy proxy_http proxy_wstunnel rewrite headers
#
# Include injected into vhost by deploy-dev.sh:
#   /etc/apache2/sites-available/optical-dev.oliver.solutions.conf
# =============================================================

# ── Timeouts for large video uploads (up to 2 GB, ~10 min) ──
<IfModule mod_proxy.c>
    ProxyTimeout 600
</IfModule>

# ── WebSocket proxy (MUST be before /api/ HTTP proxy) ────────
# ProxyPassMatch uses regex — takes precedence over Alias even when the
# physical directory /var/www/html/video-accessibility exists on disk.
# disablereuse=on keeps long-lived WS connections from blocking pool.
ProxyPassMatch ^/video-accessibility/api/v1/ws/(.*)$ ws://127.0.0.1:8012/api/v1/ws/$1 disablereuse=on
ProxyPassReverse /video-accessibility/api/v1/ws/ ws://127.0.0.1:8012/api/v1/ws/

# ── API proxy ─────────────────────────────────────────────────
# ProxyPassMatch strips /video-accessibility prefix so FastAPI sees /api/v1/...
ProxyPassMatch ^/video-accessibility/api/(.*)$ http://127.0.0.1:8012/api/$1
ProxyPassReverse /video-accessibility/api/ http://127.0.0.1:8012/api/

# Swagger / OpenAPI
ProxyPassMatch ^/video-accessibility/docs(/.*)?$ http://127.0.0.1:8012/docs$1
ProxyPassReverse /video-accessibility/docs http://127.0.0.1:8012/docs
ProxyPassMatch ^/video-accessibility/openapi\.json$ http://127.0.0.1:8012/openapi.json
ProxyPassReverse /video-accessibility/openapi.json http://127.0.0.1:8012/openapi.json

# ── SPA static files ─────────────────────────────────────────
Alias /video-accessibility /var/www/html/video-accessibility
<Directory /var/www/html/video-accessibility>
    Options -Indexes +FollowSymLinks
    AllowOverride None
    Require all granted

    # Allow large video file uploads through Apache body limit (2 GB)
    LimitRequestBody 2147483648

    RewriteEngine On
    RewriteBase /video-accessibility/

    # Serve real files/directories directly (JS, CSS, assets)
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # All other paths → index.html (React Router handles client-side nav)
    RewriteRule ^ index.html [L]
</Directory>
