RewriteEngine On

# Ensure HTTPS is being used
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Proxy requests to backend while maintaining HTTPS
RewriteRule ^(.*)$ http://127.0.0.1:3001/$1 [P,L]

# Set X-Forwarded Headers for backend
SetEnvIf HTTPS on HTTPS=1
RequestHeader set X-Forwarded-Proto "https" env=HTTPS
RequestHeader set X-Forwarded-For %{REMOTE_ADDR}s
