Skip to content

Instantly share code, notes, and snippets.

@vai
Created October 27, 2015 17:38
Show Gist options
  • Save vai/1248e92c68b8028308a8 to your computer and use it in GitHub Desktop.
Save vai/1248e92c68b8028308a8 to your computer and use it in GitHub Desktop.
Sample Angular rewrites and reverse proxy rules for IIS and Application Request Routing
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Allow-Methods" value="POST,OPTIONS,GET,PUT" />
<add name="Access-Control-Allow-Headers" value="Cache-Control,Pragma,Origin,Authorization,Content-Type,DNT,X-Requested-With,Accept,Accept-Language,Accept-Encoding" />
</customHeaders>
</httpProtocol>
<modules runAllManagedModulesForAllRequests="true" />
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" cacheControlCustom="public" />
</staticContent>
<validation validateIntegratedModeConfiguration="false" />
<directoryBrowse enabled="false" />
<security>
<requestFiltering
allowDoubleEscaping="true">
</requestFiltering>
</security>
<rewrite>
<rules>
<!-- Static Assets -->
<rule name="Assets" stopProcessing="true">
<match url="(app|assets|fonts|styles|scripts)/(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="release/{R:0}" />
</rule>
<!-- Example of a reverse proxy rule, rewriting requests from /backend to a local service on :9297 -->
<rule name="BackendProxy" stopProcessing="true">
<match url="(backend)/(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_URI}" pattern="(backend)/(.*)" />
</conditions>
<action type="Rewrite" url="http://localhost:9297/{C:2}" logRewrittenUrl="true" />
</rule>
<!-- The SPA behaviour - rewrite requests for missing files to the index page (and ignore our /api route) -->
<rule name="AngularJS App" enabled="true" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="/$" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="release/" logRewrittenUrl="true" />
</rule>
<rule name="AngularJS 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)" negate="true" />
</conditions>
<action type="Rewrite" url="release/" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
<!-- ReSharper disable once WebConfig.RedundantLocationTag -->
<location path="api">
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</location>
<location path="backend"><system.webServer><modules runAllManagedModulesForAllRequests="true" /></system.webServer></location>
<system.web>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment