<?xml version="1.0" encoding="UTF-8"?>
<!--
  IIS config for a Nibula site.

  URL Rewrite processes rules top-down and the first match with
  stopProcessing="true" wins. The default is the PHP backend, because it is the
  only one that runs on Windows shared hosting (Aruba and similar), where you
  cannot install server modules.

  To use the NODE backend instead, uncomment the "ApiToNode" rule below and
  delete "ApiToPhp". This requires a server you control, with the Application
  Request Routing and URL Rewrite modules installed and proxying enabled
  (ARR > Server Proxy Settings > Enable proxy). On shared hosting it will fail
  with a 500: rewriting to an absolute URL without ARR is not allowed.
-->
<configuration>
    <system.webServer>
        <rewrite>
            <rules>

                <!-- Block sensitive files -->
                <rule name="BlockSensitive" stopProcessing="true">
                    <match url="^(web\.config|\..*)$" ignoreCase="true" />
                    <action type="CustomResponse" statusCode="404" />
                </rule>

                <!-- PHP backend: rewrite /api to the PHP front controller. -->
                <rule name="ApiToPhp" stopProcessing="true">
                    <match url="^api/(.*)" ignoreCase="true" />
                    <action type="Rewrite" url="backend/core/index.php" appendQueryString="true" />
                </rule>

                <!-- Node backend (requires ARR). Delete "ApiToPhp" above to use this.
                <rule name="ApiToNode" stopProcessing="true">
                    <match url="^api/(.*)" ignoreCase="true" />
                    <action type="Rewrite" url="http://127.0.0.1:3000/api/{R:1}" appendQueryString="true" />
                </rule>
                -->

            </rules>
        </rewrite>

        <directoryBrowse enabled="false" />

        <httpErrors errorMode="Custom" existingResponse="Replace">
            <remove statusCode="404" />
            <remove statusCode="403" />
            <error statusCode="404" path="/404.html" responseMode="ExecuteURL" />
            <error statusCode="403" path="/404.html" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>