# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/resc4617/public_html/produkvip"
PassengerBaseURI "/"
PassengerNodejs "/home/resc4617/nodevenv/public_html/produkvip/22/bin/node"
PassengerAppType node
PassengerStartupFile app.js
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
# ============================================================================
#  PRODUK VIP — .htaccess (Clean Production Rules)
# ============================================================================
DirectoryIndex dist/index.html index.html public/index.html
Options -Indexes

<IfModule mod_headers.c>
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
    Header always set Access-Control-Allow-Headers "*"
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    <FilesMatch "\.html?$">
        Header set Cache-Control "no-cache, must-revalidate"
    </FilesMatch>
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 30 days"
    ExpiresByType image/png "access plus 30 days"
    ExpiresByType image/webp "access plus 30 days"
    ExpiresByType image/svg+xml "access plus 7 days"
    ExpiresByType font/woff2 "access plus 30 days"
    ExpiresByType text/css "access plus 1 hours"
    ExpiresByType application/javascript "access plus 1 hours"
</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json image/svg+xml
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Meneruskan Header Authorization
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # 0. Lindungi file sensitif
    RewriteRule ^(app|otpRoutes|ledgerStore|sessionAuth|realtime|mediaStore|server|find_keys|generate_apply_state)\.(c?js|ts|map)$ - [F,L]
    RewriteRule ^(private_data|node_modules|routes|src|includes|ZIP)(/.*)?$ - [F,L]

    # 1. API ditangani Node.js (Passenger)
    RewriteRule ^(api|orders|order|smm|user|webhook)(/.*)?$ - [QSA,L]

    # 1b. Root dan index.html SELALU dilayani oleh dist/index.html
    RewriteRule ^$ dist/index.html [L]
    RewriteRule ^index\.html$ dist/index.html [L]

    # 2. File fisik statis langsung jika ada
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    # 3. Aset di dalam dist/
    RewriteCond dist/$1 -f
    RewriteRule ^(.*)$ dist/$1 [L]

    RewriteCond %{DOCUMENT_ROOT}/dist/$1 -f
    RewriteRule ^(.*)$ dist/$1 [L]

    # 4. SPA fallback (seluruh halaman web dilayani dist/index.html)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ dist/index.html [L]
</IfModule>

<FilesMatch "^(\..*|serviceAccountKey.*|local_db.*|ledger.*|payment_webhook_logs\.json|digiflazz_.*\.json|otp_orders_db\.json|qrisly_.*\.json|whitelists_data\.json|metadata\.json|package(-lock)?\.json|tsconfig.*\.json|bun\.lock|.*\.(log|bak|map|sql|zip|tmp|cjs|ts|tsx|md|lock|env))$">
    Require all denied
</FilesMatch>
