# AdHub Legacy SDK - .htaccess Configuration
# Optimize delivery and enable CORS

# ==============================================================================
# CORS (Cross-Origin Resource Sharing)
# ==============================================================================
<IfModule mod_headers.c>
    # Allow loading from any origin
    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "GET, OPTIONS"
    Header set Access-Control-Allow-Headers "Content-Type"
    Header set Access-Control-Max-Age "3600"

    # Cache control for JavaScript files
    <FilesMatch "\.(js)$">
        # Cache per 1 ora (aumenta in produzione stabile: max-age=86400 per 24h)
        Header set Cache-Control "public, max-age=3600, must-revalidate"

        # Prevent caching during development (commentare in produzione)
        # Header set Cache-Control "no-cache, no-store, must-revalidate"
        # Header set Pragma "no-cache"
        # Header set Expires "0"
    </FilesMatch>

    # Security headers
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
</IfModule>

# ==============================================================================
# COMPRESSION
# ==============================================================================
<IfModule mod_deflate.c>
    # Compress JavaScript
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

# ==============================================================================
# MIME TYPES
# ==============================================================================
<IfModule mod_mime.c>
    AddType application/javascript .js
    AddType text/javascript .js
</IfModule>

# ==============================================================================
# SECURITY
# ==============================================================================

# Disable directory listing
Options -Indexes

# Disable .htaccess and other hidden files serving
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

# Only allow access to .js files
<FilesMatch "\.(js)$">
    Order allow,deny
    Allow from all
</FilesMatch>

# ==============================================================================
# HTTPS REDIRECT (opzionale - rimuovi se non usi HTTPS)
# ==============================================================================
<IfModule mod_rewrite.c>
    RewriteEngine On

    # Force HTTPS
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# ==============================================================================
# CUSTOM ERROR PAGES (opzionale)
# ==============================================================================
ErrorDocument 404 "SDK file not found. Please check the URL."
ErrorDocument 403 "Access forbidden."

# ==============================================================================
# PERFORMANCE
# ==============================================================================

# Enable Keep-Alive
<IfModule mod_headers.c>
    Header set Connection keep-alive
</IfModule>

# ==============================================================================
# LOGGING (opzionale - per debug)
# ==============================================================================
# LogLevel alert rewrite:trace3
