Skip to content

Instantly share code, notes, and snippets.

@thepirat000
Created June 29, 2024 20:01
Show Gist options
  • Save thepirat000/b0019a55722b33cf8dceeeed4ff41203 to your computer and use it in GitHub Desktop.
Save thepirat000/b0019a55722b33cf8dceeeed4ff41203 to your computer and use it in GitHub Desktop.
IIS Reverse Proxy - avoid CORS
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Reverse Proxy Rewrite URL">
<match url="proxy/(.+)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="https://{R:1}" logRewrittenUrl="true" />
</rule>
<rule name="OPTIONS returns 200" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="OPTIONS" />
</conditions>
<action type="CustomResponse" statusCode="200" statusReason="OK" statusDescription="OK" />
</rule>
</rules>
<outboundRules>
<rule name="Set-Access-Control-Allow-Origin to *">
<match serverVariable="RESPONSE_Access-Control-Allow-Origin" pattern=".+" negate="true" />
<action type="Rewrite" value="*" />
</rule>
<rule name="OPTIONS Set Access-Control-Allow-Methods for response" preCondition="OPTIONS" patternSyntax="Wildcard">
<match serverVariable="RESPONSE_Access-Control-Allow-Methods" pattern="*" />
<action type="Rewrite" value="OPTIONS,GET,POST,PATCH,PUT,DELETE" />
</rule>
<rule name="OPTIONS Set Access-Control-Allow-Origin for response" preCondition="OPTIONS" patternSyntax="Wildcard">
<match serverVariable="RESPONSE_Access-Control-Allow-Origin" pattern="*" />
<action type="Rewrite" value="*" />
</rule>
<rule name="OPTIONS Set Access-Control-Allow-Headers for response" preCondition="OPTIONS" patternSyntax="Wildcard">
<match serverVariable="RESPONSE_Access-Control-Allow-Headers" pattern="*" />
<action type="Rewrite" value="*" />
</rule>
<rule name="OPTIONS Set Access-Control-Max-Age for response" preCondition="OPTIONS" patternSyntax="Wildcard">
<match serverVariable="RESPONSE_Access-Control-Max-Age" pattern="*" />
<action type="Rewrite" value="3600" />
</rule>
<preConditions>
<preCondition name="OPTIONS" patternSyntax="Wildcard">
<add input="{REQUEST_METHOD}" pattern="OPTIONS" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment