# Vhost Apache — Frontend Enjay (Nuxt/Nitro)
#
# ⚠️ SERVEUR cPANEL (ns3190545) : ce fichier ne convient PAS — cPanel régénère
#    httpd.conf et son vhost de sous-domaine reprend la main. La prod passe par
#    les includes userdata posés par deploy-almalinux/install.sh (phase 6),
#    qui proxifient front. → 127.0.0.1:3100 (3000 = ESTAIR). Ce fichier reste
#    une RÉFÉRENCE pour un serveur Apache non-cPanel.
#
# ⚠️ REVERSE-PROXY, PAS DE DocumentRoot.
# Ne JAMAIS servir .output/public/ en statique : les appels /api/proxy/* (routes
# serveur Nitro qui injectent les clés d'API secrètes) renverraient 404 et l'app
# serait morte. Tout doit passer par le process Node (systemd enjay-frontend).
#
# Prérequis :
#   dnf install -y mod_ssl
#   Modules : mod_proxy, mod_proxy_http
#   SELinux : setsebool -P httpd_can_network_connect 1   ← sinon 503 opaque
#
# Installation :
#   sudo cp deploy/apache/enjay-frontend.conf /etc/httpd/conf.d/
#   sudo apachectl configtest && sudo systemctl reload httpd

<VirtualHost *:80>
    ServerName app.enjay.example.com
    # ACME/Let's Encrypt doit rester accessible en clair
    Alias /.well-known/acme-challenge/ /var/www/acme/.well-known/acme-challenge/
    <Directory "/var/www/acme">
        Require all granted
    </Directory>
    RedirectMatch 301 ^/(?!\.well-known/acme-challenge/)(.*)$ https://app.enjay.example.com/$1
</VirtualHost>

<VirtualHost *:443>
    ServerName app.enjay.example.com

    SSLEngine on
    SSLCertificateFile      /etc/letsencrypt/live/app.enjay.example.com/fullchain.pem
    SSLCertificateKeyFile   /etc/letsencrypt/live/app.enjay.example.com/privkey.pem

    ProxyPreserveHost On
    ProxyRequests Off

    # Le front lit l'origine réelle (redirectUri Keycloak = window.location.origin)
    RequestHeader set X-Forwarded-Proto "https"

    ProxyPass        / http://127.0.0.1:3100/
    ProxyPassReverse / http://127.0.0.1:3100/

    ErrorLog  /var/log/httpd/enjay-frontend_error.log
    CustomLog /var/log/httpd/enjay-frontend_access.log combined
</VirtualHost>
