<?xml version="1.0"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="React Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(api|\.well-known)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>
      </rules>
      <outboundRules>
        <!-- Set no-store for HTML responses -->
        <rule name="NoCacheHtml" preCondition="IsHtml">
          <match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
          <action type="Rewrite" value="no-store, no-cache, must-revalidate, max-age=0" />
        </rule>
        <!-- Cache hashed static assets aggressively -->
        <rule name="CacheStaticAssets" preCondition="IsAsset">
          <match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
          <action type="Rewrite" value="public, max-age=31536000, immutable" />
        </rule>
        <preConditions>
          <preCondition name="IsHtml">
            <add input="{RESPONSE_Content-Type}" pattern="^text/html" />
          </preCondition>
          <preCondition name="IsAsset">
            <add input="{REQUEST_URI}" pattern="\.(js|css|png|jpg|jpeg|gif|svg|webp|woff|woff2|ttf|eot)$" />
          </preCondition>
        </preConditions>
      </outboundRules>
    </rewrite>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <!-- Extensionless files: apple-app-site-association (mobile deep links) must be served as JSON -->
      <remove fileExtension="." />
      <mimeMap fileExtension="." mimeType="application/json" />
      <mimeMap fileExtension=".webmanifest" mimeType="application/manifest+json" />
    </staticContent>
  </system.webServer>
</configuration> 