# Prevent caching of index.html so users always get the latest version
<IfModule mod_headers.c>
  <FilesMatch "index\.html$">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0
  </FilesMatch>
  
  # Cache static assets with hashed filenames for 1 year
  <FilesMatch "\.(js|css|woff2?|ttf|eot|svg|png|jpg|jpeg|gif|ico|webp)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>

  # Service-worker kill-switch files must never be cached, otherwise old
  # preview/published shells can keep serving stale designs.
  <FilesMatch "^(sw|service-worker)\.js$">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0
  </FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # ── Public Seller API: app.kjemibasen.no/api/v1/* → Edge Function ──
  # Requires mod_proxy + mod_proxy_http (enabled by default on most cPanel hosts)
  RewriteRule ^api/v1/(.*)$ https://phrfigrzzfcqjlponibk.supabase.co/functions/v1/seller-api/$1 [P,L]

  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>
