# WhatsApp Survey Bot - Apache Proxy Configuration
# This file should be placed in public_html directory

RewriteEngine On

# Enable proxy module
RewriteOptions inherit

# Proxy all requests to Node.js app running on port 3000
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P,L]

# Set proxy headers
RewriteRule ^(.*)$ - [E=HTTP_X_FORWARDED_FOR:%{REMOTE_ADDR}]
RewriteRule ^(.*)$ - [E=HTTP_X_FORWARDED_PROTO:%{HTTPS:on}]

# Handle WebSocket connections for real-time features
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^(.*)$ ws://127.0.0.1:3000/$1 [P,L]

# Security headers
Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options DENY
Header always set X-XSS-Protection "1; mode=block"

# Cache static assets
<FilesMatch "\.(css|js|png|jpg|jpeg|gif|ico|svg)$">
    ExpiresActive On
    ExpiresDefault "access plus 1 month"
</FilesMatch>