<IfModule mod_rewrite.c>
    RewriteEngine On
    
    # If the request is for an existing file or directory, serve it directly
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    # For API requests, proxy to Node.js
    RewriteCond %{REQUEST_URI} ^/api/
    RewriteRule ^api/(.*)$ http://localhost:3000/api/$1 [P,L]
    
    # For all other requests, serve the index.html file
    RewriteRule ^ index.html [L]
</IfModule>

# Set security headers
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-XSS-Protection "1; mode=block"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>
