# =============================================================
# OPTIMASI PENUH TOTAL - DOMAIN ROOT (gurukuring / gurusae.id)
# Mengontrol & Membatasi Proses di Semua Subdomain
# =============================================================

Options -MultiViews
RewriteEngine On

# ===================================================
# 1. BATASI PROCESS PASSENGER SANGAT STRICT (MAX 1 INSTANCE TOTAL)
#    Mencegah Lonjakan Proses Menuju Limit 40/40
# ===================================================
<IfModule mod_passenger.c>
    PassengerMaxInstances 1
    PassengerMinInstances 0
    PassengerPoolIdleTime 30
    PassengerHighPerformance off
    PassengerStatThrottleRate 10
</IfModule>

# ===================================================
# 2. STRATEGI CACHING PROXY & HEADER OPTIMIZATION
#    Dynamic Requests (API) Tidak Boleh Dicache
# ===================================================
<IfModule mod_headers.c>
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Credentials "true"
    Header always set Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
    Header always set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With"
</IfModule>

# Tangani Preflight OPTIONS langsung di Server (0 Proses Node.js)
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ - [R=200,L]

# Direct Caching untuk Static Asset (Mengurangi Beban CPU Server hingga 90%)
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType font/woff2 "access plus 1 month"
</IfModule>

<IfModule LiteSpeed>
    RewriteCond %{REQUEST_METHOD} ^(PUT|POST|PATCH|DELETE)$
    RewriteRule .* - [E=no-cache:1]
    CacheLookup off
</IfModule>
