<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin admin@mcube.com
    ServerName app2.syntheon.in
    ServerAlias app2.syntheon.in

    DocumentRoot /var/www/html

    # Proxy /voicebot to Next.js app on port 3000 (includes frontend UI and API routes)
    <Location /voicebot>
        ProxyPreserveHost On
        ProxyPass http://localhost:3000/voicebot
        ProxyPassReverse http://localhost:3000/voicebot
    </Location>

    # WebSocket support for LiveKit
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule ^/voicebot/(.*)$ ws://localhost:3000/voicebot/$1 [P,L]

    # Default directory for other paths
    <Directory /var/www/html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    <FilesMatch \.php$>
        SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost/"
    </FilesMatch>

    ErrorLog ${APACHE_LOG_DIR}/app2.syntheon.in-error.log
    CustomLog ${APACHE_LOG_DIR}/app2.syntheon.in-access.log combined

    SSLEngine on
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/app2.syntheon.in/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/app2.syntheon.in/privkey.pem
</VirtualHost>
</IfModule>
