# Mastreams Flutter Web — Namecheap shared hosting config

# Enable rewrite engine
Options -MultiViews
RewriteEngine On

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

# Set correct MIME types for Flutter web assets
AddType application/javascript .js .mjs
AddType application/wasm .wasm
AddType application/json .json

# Cache static assets aggressively
<FilesMatch "\.(wasm|js|css|png|jpg|ico|otf|ttf|frag)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>

# Don't cache index.html or service worker
<FilesMatch "(index\.html|flutter_service_worker\.js|flutter_bootstrap\.js|manifest\.json)$">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "0"
</FilesMatch>

# Required headers for SharedArrayBuffer (skwasm renderer)
<IfModule mod_headers.c>
    Header set Cross-Origin-Opener-Policy "same-origin"
    Header set Cross-Origin-Embedder-Policy "require-corp"
</IfModule>

# Flutter web routing — serve index.html for all routes
# so Flutter's router handles the navigation client-side
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

# Compress text assets
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html application/javascript application/json text/css
</IfModule>
