# Written by dartvel build web. Rewritten on every build while this line is
# here. To keep your own edits, delete this line: the build then leaves the
# file alone. Or put your own in the project's web/.htaccess, which the build
# copies in place of this one.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Served as themselves. Without these the fallback below swallows every
  # asset and the page loads index.html as its own JavaScript.
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  # Everything else is a route. The application reads the URL and renders it.
  RewriteRule . /index.html [L]
</IfModule>

# Where mod_rewrite is off. The rewrite above sends unknown paths to the
# application shell, which is right for a route the router knows and wrong for
# one nothing does -- and it does not run at all on a host without
# mod_rewrite, where this is what a visitor sees instead of the server's own
# branding.
ErrorDocument 404 /404/index.html

# The Universal Links document has no extension for AddType to match, and iOS
# refuses it as anything but JSON.
<Files "apple-app-site-association">
  ForceType application/json
</Files>

<IfModule mod_mime.c>
  # instantiateStreaming refuses a wasm module served as anything else.
  AddType application/wasm .wasm
  AddType application/javascript .js
  AddType application/json .json
</IfModule>

<IfModule mod_headers.c>
  # The headers a Dartvel server sends on every response, so a static host
  # answers the same: no sniffing a file into another type, no framing by
  # another site, and no full URL leaking to other origins. setifempty keeps
  # one the host already sends.
  Header always setifempty X-Content-Type-Options "nosniff"
  Header always setifempty X-Frame-Options "SAMEORIGIN"
  Header always setifempty Referrer-Policy "strict-origin-when-cross-origin"
  # Not cached, because Flutter does not content-hash any of these: a build
  # from today and a build from last year both produce a file called
  # main.dart.js. A blanket immutable rule over *.js froze the site for every
  # returning visitor -- no error, no way for them to know, and no way out
  # from their side once the service worker was cached too.
  <FilesMatch "^(index\.html|main\.dart\.js|flutter_bootstrap\.js|flutter_service_worker\.js|version\.json|manifest\.json)$">
    Header set Cache-Control "no-cache, must-revalidate"
  </FilesMatch>

  # These do carry a version in their path, and they are the large ones.
  <FilesMatch "^(canvaskit/|assets/).*\.(js|wasm|woff2|otf|ttf|png|jpg|svg|json)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
</IfModule>
