<VirtualHost *:80>
    ServerName eta.vbarco.com.br

    DocumentRoot /var/www/html/ETA

    # Proxy para o WebSocket do ETA Engine
    ProxyPreserveHost On
    
    # WebSocket endpoint
    ProxyPass /ws ws://localhost:8081/ws
    ProxyPassReverse /ws ws://localhost:8081/ws

    # Health check endpoint
    ProxyPass /health http://localhost:8081/health
    ProxyPassReverse /health http://localhost:8081/health

    # Configuração para WebSocket
    <Location /ws>
        RewriteEngine On
        RewriteCond %{HTTP:Upgrade} =websocket [NC]
        RewriteRule /(.*)           ws://localhost:8081/$1 [P,L]
        RewriteCond %{HTTP:Upgrade} !=websocket [NC]
        RewriteRule /(.*)           http://localhost:8081/$1 [P,L]
        
        ProxyPass ws://localhost:8081/ws
        ProxyPassReverse ws://localhost:8081/ws
    </Location>

    # Logs
    ErrorLog ${APACHE_LOG_DIR}/eta-vbarco-error.log
    CustomLog ${APACHE_LOG_DIR}/eta-vbarco-access.log combined

    # Redirect HTTP to HTTPS (será adicionado pelo certbot)
</VirtualHost>
