<?xml version="1.0" encoding="UTF-8"?>
<!--
  Kindie — IIS reverse proxy example (Windows Server)

  Prerequisites (install once via Web Platform Installer or the MSI downloads):
    - IIS with the "Application Request Routing" (ARR) module
    - IIS "URL Rewrite" module
    - In IIS Manager, click the server name (top of the tree) -> "Application
      Request Routing Cache" -> "Server Proxy Settings..." -> check "Enable
      proxy" -> Apply. This one step is required, or every request below
      returns a 502.
    - In IIS Manager, open "URL Rewrite" for the server -> "View Server
      Variables..." -> "Add..." -> HTTP_X_FORWARDED_PROTO. Without it, IIS
      answers 500.50 on every request below.
    - Windows feature "WebSocket Protocol" (Server Manager -> Add roles and
      features -> Web Server -> Application Development), needed for chat.

  1. Create a new IIS site (or use Default Web Site) with its physical path
     set to an empty folder, and bind it to your domain on ports 80/443.
  2. Copy this file into that folder, renamed to "web.config".
  3. Get an SSL certificate with win-acme (free, Let's Encrypt) — run wacs.exe
     as Administrator and follow the prompts; it also binds the certificate
     to your site for you.

  This file assumes the site is served over HTTPS only, so it tells Kindie the
  original request was "https".

  See "Customization" -> "Change the default web server" in the Kindie user
  guide for the full walkthrough.
-->
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Kindie reverse proxy" stopProcessing="true">
          <match url="(.*)" />
          <action type="Rewrite" url="http://127.0.0.1:1337/{R:1}" />
          <serverVariables>
            <!-- Required so the app knows it's being served over HTTPS
                 (secure cookies, correct links in outgoing email). -->
            <set name="HTTP_X_FORWARDED_PROTO" value="https" replace="true" />
          </serverVariables>
        </rule>
      </rules>
    </rewrite>
    <!-- Allow uploads (photos, documents, chat videos) up to 100 MB, the same limit as Kindie itself. -->
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="104857600" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>
