<VirtualHost *:80>
    ServerName odycrm.softcomp.io
    ServerAlias www.odycrm.softcomp.io
    
    # Redirect HTTP to HTTPS
    Redirect permanent / https://odycrm.softcomp.io/
</VirtualHost>

<VirtualHost *:443>
    ServerName odycrm.softcomp.io
    ServerAlias www.odycrm.softcomp.io
    
    # SSL Configuration
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/odycrm.softcomp.io/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/odycrm.softcomp.io/privkey.pem
    
    # Security headers (iframe-friendly)
    Header always set X-Content-Type-Options nosniff
    Header always set X-XSS-Protection "1; mode=block"
    
    # Proxy to Next.js CRM application (port 3001)
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:3001/
    ProxyPassReverse / http://127.0.0.1:3001/
    
    # Handle WebSocket connections
    RewriteEngine on
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule ^/?(.*) "ws://127.0.0.1:3001/$1" [P,L]
    
    # Logs
    ErrorLog ${APACHE_LOG_DIR}/odycrm.softcomp.io-error.log
    CustomLog ${APACHE_LOG_DIR}/odycrm.softcomp.io-access.log combined
</VirtualHost>
