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

    # Enable proxy modules
    ProxyPreserveHost On
    ProxyRequests Off

    # WebSocket proxy configuration
    # Proxy WebSocket connections to FastAPI app
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule ^/ws/(.*)$ ws://127.0.0.1:7900/ws/$1 [P,L]

    # Proxy all HTTP requests to FastAPI app
    ProxyPass / http://127.0.0.1:7900/
    ProxyPassReverse / http://127.0.0.1:7900/

    # WebSocket specific proxy pass (alternative method)
    ProxyPass /ws/ ws://127.0.0.1:7900/ws/
    ProxyPassReverse /ws/ ws://127.0.0.1:7900/ws/

    # Error and access logs
    ErrorLog ${APACHE_LOG_DIR}/catalyst.syntheon.in-error.log
    CustomLog ${APACHE_LOG_DIR}/catalyst.syntheon.in-access.log combined
</VirtualHost>

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

        # Enable proxy modules
        ProxyPreserveHost On
        ProxyRequests Off

        # WebSocket proxy configuration for HTTPS/WSS
        # Proxy WebSocket connections to FastAPI app
        RewriteEngine On
        RewriteCond %{HTTP:Upgrade} websocket [NC]
        RewriteCond %{HTTP:Connection} upgrade [NC]
        RewriteRule ^/ws/(.*)$ ws://127.0.0.1:7900/ws/$1 [P,L]

        # Proxy all HTTP requests to FastAPI app
        ProxyPass / http://127.0.0.1:7900/
        ProxyPassReverse / http://127.0.0.1:7900/

        # WebSocket specific proxy pass (WSS - WebSocket Secure)
        ProxyPass /ws/ ws://127.0.0.1:7900/ws/
        ProxyPassReverse /ws/ ws://127.0.0.1:7900/ws/

        # 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

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

