# /etc/apache2/sites-available/sudoku-studio.conf

<VirtualHost *:80>
    ServerName sudoku.brchad.com

    # Redireciona tudo para HTTPS
    RewriteEngine On
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>

<VirtualHost *:443>
    ServerName sudoku.brchad.com

    # SSL (preenchido pelo certbot automaticamente)
    SSLEngine on
    SSLCertificateFile    /etc/letsencrypt/live/sudoku.brchad.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/sudoku.brchad.com/privkey.pem

    # Passa todas as requisições para o Node.js
    ProxyPreserveHost On
    ProxyPass        / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/

    # Repassa o IP real do visitante para o Node.js
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Real-IP %{REMOTE_ADDR}s

    # Logs
    ErrorLog  ${APACHE_LOG_DIR}/sudoku-error.log
    CustomLog ${APACHE_LOG_DIR}/sudoku-access.log combined
</VirtualHost>
