ServerName localhost

# Listen on port 80 (HTTP)
Listen 80

# Listen on port 443 (HTTPS)
Listen 443

# Load essential modules
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule alias_module modules/mod_alias.so
LoadModule headers_module modules/mod_headers.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule expires_module modules/mod_expires.so
LoadModule filter_module modules/mod_filter.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule unixd_module modules/mod_unixd.so

# Load mod_socache_shmcb for SSL session caching
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule dir_module modules/mod_dir.so

# Configure SSL session cache
SSLSessionCache shmcb:/var/cache/apache2/ssl_scache(512000)
SSLSessionCacheTimeout 300

# HTTP VirtualHost (Port 80)
<VirtualHost *:80>
    ServerName uat-taxary.pheonixsolutions.com
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} !^/graphql
    RewriteRule ^(.*)$ https://uat-taxary.pheonixsolutions.com/$1 [R=301,L]
</VirtualHost>

# HTTPS VirtualHost (Port 443)
<VirtualHost *:443>
    ServerName uat-taxary.pheonixsolutions.com
    # SSL/TLS configuration
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/uat-taxary.pheonixsolutions.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/uat-taxary.pheonixsolutions.com/privkey.pem
   
    ProxyPass /graphql http://uat-taxary.pheonixsolutions.com-server:5002/graphql
    ProxyPassReverse /graphql http://uat-taxary.pheonixsolutions.com-server:5002/graphql

    # Serve static frontend files
    DocumentRoot "/usr/local/apache2/htdocs/"
    <Directory "/usr/local/apache2/htdocs/">
        Require all granted
        AllowOverride All
        Options FollowSymLinks
        DirectoryIndex index.html index.htm

        # Rewrite for SPA routes (e.g., /main, /dashboard, etc.)
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^ index.html [L]
    </Directory>

    # Log errors
    ErrorLog /proc/self/fd/2
    CustomLog /proc/self/fd/1 combined
</VirtualHost>
