# Deviant beta — Apache config for static hosting at a SUBDOMAIN ROOT
# (shared hosting / cPanel). Upload the CONTENTS of dist/ to the subdomain's
# document root; this file ships inside dist/ and applies automatically.
# (Ignored by static hosts like Netlify/Cloudflare Pages — safe to leave in.)

# ── Force HTTPS — WebCrypto (crypto.subtle) and the PWA require a secure context.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ── SPA fallback: serve index.html for any path that is not a real file/dir.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.html [L]

# ── Correct MIME types.
<IfModule mod_mime.c>
  AddType application/manifest+json .webmanifest
  AddType image/svg+xml            .svg
  AddType text/javascript          .js
</IfModule>

# ── Caching. Hashed assets (assets/*.js|css) are immutable; the HTML, service
#    worker, and manifest must NOT be cached, so testers always get fresh code.
<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|svg|woff2?)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
  # These override the rule above for the entry points (FilesMatch is evaluated
  # in order; the later Header set wins for the same header).
  <FilesMatch "^(index\.html|sw\.js|manifest\.webmanifest)$">
    Header set Cache-Control "no-cache, max-age=0, must-revalidate"
  </FilesMatch>
</IfModule>
