# Apache config for the AskTox SPA on cPanel. Vite copies everything in client/public into
# dist/, so uploading dist/ to public_html brings this with it.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Client-side routing: React Router owns paths like /ask/<id> and /chat, but Apache looks
  # for a matching file on disk and returns 404 for all of them. Without this, the app works
  # while navigating but breaks on refresh, on a shared link, and on browser Back - which
  # reads as "the site is broken" rather than "routing is misconfigured".
  # Real files and directories are served normally, so hashed assets are unaffected.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

<IfModule mod_headers.c>
  # Vite fingerprints asset filenames, so they can be cached indefinitely - a changed file
  # gets a new name.
  <FilesMatch "\.(js|css|woff2?|png|jpe?g|svg|webp|ico)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>

  # index.html must NOT be cached: it is the only file whose name never changes, so a cached
  # copy keeps pointing at the previous deploy's asset filenames and the site silently serves
  # a stale build - or a blank page once those assets are cleaned up.
  <FilesMatch "^index\.html$">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
  </FilesMatch>

  Header set X-Content-Type-Options "nosniff"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# Serve the correct MIME type for source maps and fonts if the host's defaults are thin.
<IfModule mod_mime.c>
  AddType application/javascript .js
  AddType font/woff2 .woff2
</IfModule>
