<?xml version="1.0" encoding="UTF-8"?>
<!--
  ====================================================================
  ROA2WEB - IIS Sub-Application Configuration
  ====================================================================

  ⚠️ CRITICAL - For IIS Sub-Application Deployment! ⚠️

  This web.config is for when IIS is configured as SUB-APPLICATION:
  - IIS Application Path: /roa2web
  - Physical Path: C:\inetpub\wwwroot\roa2web\frontend (or dist/)

  **How IIS Sub-Applications Work**:
  - Browser request: https://example.com/roa2web/api/auth/login
  - IIS application PATH strips the "/roa2web" prefix
  - Inside application: request arrives as /api/auth/login
  - Therefore: URL patterns must NOT include "roa2web/" prefix!

  **Production Architecture (2-Tier IIS)**:

  Public Server (10.0.20.122 - roa2web.romfast.ro)
    └─ Proxies ALL to → https://10.0.20.36/{REQUEST_PATH}

  Internal Server (10.0.20.36)
    └─ IIS Sub-App: /roa2web → Physical: C:\inetpub\wwwroot\roa2web\frontend
        └─ This web.config proxies /api/* to localhost:8000

  See: deployment/windows/docs/TWO-TIER-IIS-DEPLOYMENT.md

  ====================================================================
-->
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <!-- Proxy API requests to unified backend on localhost -->
        <!-- NOTE: NO /roa2web/ prefix - IIS sub-app already stripped it! -->
        <rule name="Proxy Unified API" stopProcessing="true">
          <match url="^api/(.*)" />
          <action type="Rewrite" url="http://localhost:8000/api/{R:1}" />
        </rule>

        <!-- Proxy uploads to unified backend on localhost -->
        <rule name="Proxy Uploads" stopProcessing="true">
          <match url="^uploads/(.*)" />
          <action type="Rewrite" url="http://localhost:8000/uploads/{R:1}" />
        </rule>

        <!-- SPA fallback - all other routes serve index.html -->
        <rule name="SPA Fallback" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.html" />
        </rule>
      </rules>
    </rewrite>

    <!-- Static content configuration -->
    <staticContent>
      <!-- Remove first to avoid duplicates with server-level config, then add -->
      <remove fileExtension=".webmanifest" />
      <mimeMap fileExtension=".webmanifest" mimeType="application/manifest+json" />
      <remove fileExtension=".js" />
      <mimeMap fileExtension=".js" mimeType="application/javascript" />
      <remove fileExtension=".json" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>

    <!-- Client cache for static assets (1 year) -->
    <httpProtocol>
      <customHeaders>
        <add name="Cache-Control" value="public, max-age=31536000" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>
