# ============================================================
# Nowills PMS — Apache / cPanel configuration
# ============================================================

# Serve the dashboard as the folder default document
DirectoryIndex index.html

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

# ---------- GZIP / Brotli compression ----------
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript
  AddOutputFilterByType DEFLATE application/javascript application/json
  AddOutputFilterByType DEFLATE application/manifest+json image/svg+xml
</IfModule>

# ---------- Browser caching ----------
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css               "access plus 7 days"
  ExpiresByType text/javascript        "access plus 7 days"
  ExpiresByType application/javascript "access plus 7 days"
  ExpiresByType image/jpeg             "access plus 30 days"
  ExpiresByType image/svg+xml          "access plus 30 days"
  # Never cache the shell or the service worker - staff must get updates instantly
  ExpiresByType text/html              "access plus 0 seconds"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(html)$">
    Header set Cache-Control "no-cache, must-revalidate"
  </FilesMatch>
  <FilesMatch "sw\.js$">
    Header set Cache-Control "no-cache, must-revalidate"
    Header set Service-Worker-Allowed "/"
  </FilesMatch>
  # Baseline security headers
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# ---------- Force HTTPS (required for PWA / offline mode) ----------
# Uncomment the three lines below once your SSL certificate is active.
# <IfModule mod_rewrite.c>
#   RewriteEngine On
#   RewriteCond %{HTTPS} !=on
#   RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# </IfModule>

# ---------- Hide dotfiles ----------
<FilesMatch "^\.">
  Require all denied
</FilesMatch>
