# TrendSync Frontend - cPanel .htaccess Configuration

RewriteEngine On

# Redirect HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Handle Next.js routing
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.html [L]

<IfModule mod_headers.c>

    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"

    Header always set Content-Security-Policy "
        default-src 'self';
        script-src 'self' 'unsafe-inline' 'unsafe-eval'
            https://apis.google.com
            https://accounts.google.com
            https://*.googleapis.com
            https://*.gstatic.com;
        style-src 'self' 'unsafe-inline'
            https://fonts.googleapis.com
            https://api.fontshare.com;
        font-src 'self'
            https://fonts.gstatic.com
            https://api.fontshare.com;
        img-src 'self' data: https:;
        connect-src 'self'
            https://*.googleapis.com
            https://*.google.com
            https://securetoken.googleapis.com
            https://identitytoolkit.googleapis.com
            https://*.firebaseio.com
            wss://*.firebaseio.com
            https://*.firebaseapp.com
            https://*.run.app
            https://*.google-analytics.com;
        frame-src
            https://accounts.google.com
            https://*.firebaseapp.com;
    "

</IfModule>

# Gzip compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule>

# Cache static assets
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/json "access plus 0 seconds"
    ExpiresByType text/html "access plus 0 seconds"
</IfModule>

Options -Indexes

<FilesMatch "\.(env|log|json|md)$">
    Order allow,deny
    Deny from all
</FilesMatch>