<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Uploads Proxy" stopProcessing="true">
          <match url="^uploads/(.*)" />
          <action type="Rewrite" url="http://localhost:3000/uploads/{R:1}" />
        </rule>
        <!-- API反向代理规则 -->
        <rule name="API Proxy" stopProcessing="true">
          <match url="^api/(.*)" />
          <action type="Rewrite" url="http://localhost:3000/api/{R:1}" />
        </rule>
        <!-- Vue Router规则：仅对无扩展名的路由请求重写到 index.html -->
        <!-- 关键：带文件扩展名的请求（如 /assets/index-xxx.js）绝不兜底， -->
        <!-- 否则缺失的 bundle 会被返回成 text/html，浏览器把 HTML 当 JS 加载 -->
        <!-- 导致脚本执行失败、启动屏永不隐藏、版本自检永不运行。 -->
        <rule name="Vue Router" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <!-- 跳过带扩展名的请求（.js .css .png .json .woff 等），让 IIS 静态处理器返回真实 404 -->
            <add input="{REQUEST_URI}" pattern="\.\w{1,8}($|\?)" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/api" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/uploads" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>
      </rules>
    </rewrite>

    <staticContent>
      <!-- 默认：所有静态文件长缓存 1 年（assets 都带内容 hash，文件内容变即文件名变，安全） -->
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />

      <!-- 原有 MIME 类型 -->
      <remove fileExtension=".json" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="font/woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
      <!-- 新增：拆包后可能产生的 .mjs 文件 -->
      <remove fileExtension=".mjs" />
      <mimeMap fileExtension=".mjs" mimeType="application/javascript" />
    </staticContent>

    <!-- 启用 gzip 静态压缩（IIS 自带功能） -->
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
  </system.webServer>

  <!-- index.html 不再单独设 Cache-Control：no-cache/no-store 在 iOS 微信 WKWebView 下会触发
       进度条卡死/页面打不开。index.html 走默认 clientCache（长缓存），版本更新由 onLaunch
       的静默版本检测（checkVersion）+ 自愈脚本（bundle 404 兜底）负责。 -->
</configuration>
