<VirtualHost *:80>
    ServerName catalyst.syntheon.in
    ServerAlias www.catalyst.syntheon.in
    
    # Redirect HTTP to HTTPS
    Redirect permanent / https://catalyst.syntheon.in/
</VirtualHost>

<VirtualHost *:443>
    ServerName catalyst.syntheon.in
    ServerAlias www.catalyst.syntheon.in
    ServerAdmin webmaster@localhost

    # SSL Configuration
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/catalyst.syntheon.in/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/catalyst.syntheon.in/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
    
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>

    # Enable proxy modules
    ProxyPreserveHost On
    ProxyRequests Off
    
    # Enable Rewrite Engine for WebSocket upgrade detection
    RewriteEngine On
    
    # WebSocket upgrade detection and proxy
    # This detects WebSocket upgrade requests and proxies them correctly
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule ^/ws/(.*)$ ws://127.0.0.1:7900/ws/$1 [P,L]
    
    # Proxy WebSocket connections (alternative method)
    ProxyPass /ws/ ws://127.0.0.1:7900/ws/
    ProxyPassReverse /ws/ ws://127.0.0.1:7900/ws/
    
    # Proxy all other HTTP requests to FastAPI
    ProxyPass / http://127.0.0.1:7900/
    ProxyPassReverse / http://127.0.0.1:7900/
    
    # Error and access logs
    ErrorLog ${APACHE_LOG_DIR}/catalyst.syntheon.in-ssl-error.log
    CustomLog ${APACHE_LOG_DIR}/catalyst.syntheon.in-ssl-access.log combined
</VirtualHost>

