# Configuração do Apache para Laravel em subdiretório /shopifyapi
# Domínio: jcwebsoftware.cloud

<VirtualHost *:80>
    ServerName jcwebsoftware.cloud
    DocumentRoot /var/www/html
    
    # Redirecionar HTTP para HTTPS
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # Configuração para subdiretório /shopifyapi
    Alias /shopifyapi /var/www/html/shopify-api/public
    
    <Directory /var/www/html/shopify-api/public>
        AllowOverride All
        Require all granted
        
        # Configurações específicas do Laravel
        DirectoryIndex index.php
        
        # Headers de segurança
        Header always set X-Content-Type-Options nosniff
        Header always set X-Frame-Options DENY
        Header always set X-XSS-Protection "1; mode=block"
        
        # Configurações de cache para assets
        <FilesMatch "\.(css|js|png|jpg|jpeg|gif|ico|svg)$">
            ExpiresActive On
            ExpiresDefault "access plus 1 month"
            Header append Cache-Control "public"
        </FilesMatch>
    </Directory>
    
    # Logs específicos para a API
    ErrorLog ${APACHE_LOG_DIR}/shopify-api_error.log
    CustomLog ${APACHE_LOG_DIR}/shopify-api_access.log combined
    
    # Limite de upload (ajuste conforme necessário)
    LimitRequestBody 10485760  # 10MB
    
    # Timeout configurations
    Timeout 300
    KeepAliveTimeout 5
    MaxKeepAliveRequests 100
</VirtualHost>

# Configuração HTTPS (recomendado)
<VirtualHost *:443>
    ServerName jcwebsoftware.cloud
    DocumentRoot /var/www/html
    
    # Certificado SSL
    SSLEngine on
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/jcwebsoftware.cloud/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/jcwebsoftware.cloud/privkey.pem
    
    # Configuração para subdiretório /shopifyapi
    Alias /shopifyapi /var/www/html/shopify-api/public
    
    <Directory /var/www/html/shopify-api/public>
        AllowOverride All
        Require all granted
        
        # Configurações específicas do Laravel
        DirectoryIndex index.php
        
        # Headers de segurança
        Header always set X-Content-Type-Options nosniff
        Header always set X-Frame-Options DENY
        Header always set X-XSS-Protection "1; mode=block"
        Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
        
        # Configurações de cache para assets
        <FilesMatch "\.(css|js|png|jpg|jpeg|gif|ico|svg)$">
            ExpiresActive On
            ExpiresDefault "access plus 1 month"
            Header append Cache-Control "public"
        </FilesMatch>
    </Directory>
    
    # Logs específicos para a API
    ErrorLog ${APACHE_LOG_DIR}/shopify-api_ssl_error.log
    CustomLog ${APACHE_LOG_DIR}/shopify-api_ssl_access.log combined
    
    # Limite de upload (ajuste conforme necessário)
    LimitRequestBody 10485760  # 10MB
    
    # Timeout configurations
    Timeout 300
    KeepAliveTimeout 5
    MaxKeepAliveRequests 100
</VirtualHost>
