# Standalone Apache vhost — serves the built dashboard (frontend) AND reverse-proxies the
# Flask backend, all in this one file. Use this instead of apache-proxy-snippet.conf when you
# control the full vhost yourself (not pasting into WHM's Include Editor, which already manages
# DocumentRoot/SSL for you — for that case keep using apache-proxy-snippet.conf).
#
# ============================ EDIT THESE BEFORE DEPLOYING ============================
# Path to the built dashboard, i.e. the contents of backend/static (index.html + assets/).
# Update this any time the deploy path changes.
Define DASHBOARD_ROOT "/CHANGE/ME/path/to/dashboard/static"

Define APP_DOMAIN     "pandabugsreporting.com"
Define BACKEND_ORIGIN "http://97.74.90.109:8000"

# TLS certificate files (e.g. cPanel AutoSSL puts these under
# /etc/pki/tls/certs/<domain>.crt and /etc/pki/tls/private/<domain>.key,
# or a certbot install puts them under /etc/letsencrypt/live/<domain>/).
Define SSL_CERT_FILE  "/CHANGE/ME/fullchain.pem"
Define SSL_KEY_FILE   "/CHANGE/ME/privkey.pem"
# =======================================================================================

<IfModule mod_ssl.c>
<VirtualHost *:80>
    ServerName ${APP_DOMAIN}
    Redirect permanent / https://${APP_DOMAIN}/
</VirtualHost>

<VirtualHost *:443>
    ServerName   ${APP_DOMAIN}
    DocumentRoot "${DASHBOARD_ROOT}"

    SSLEngine on
    SSLCertificateFile    "${SSL_CERT_FILE}"
    SSLCertificateKeyFile "${SSL_KEY_FILE}"

    # /api/* -> the dockerized Flask backend (matches docker-compose.yml's "8000:8000").
    # Kept out of the static <Directory> block below so it's never shadowed by the SPA fallback.
    ProxyPreserveHost On
    ProxyPass        /api "${BACKEND_ORIGIN}/api"
    ProxyPassReverse /api "${BACKEND_ORIGIN}/api"

    <Directory "${DASHBOARD_ROOT}">
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Require all granted

        # SPA fallback: any non-file, non-api path falls through to index.html so React
        # Router's client-side routes (e.g. /projects/1/issues/2) work on a hard refresh.
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_URI} !^/api
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^ index.html [L]
    </Directory>
</VirtualHost>
</IfModule>
