Reputation: 5774
I have one web app hosted in Azure websites. I am consuming API from another level (having method PUT, POST, GET, DELETE).. I want to make my web app compatible with IE8 and IE9 but unfortunately, it does not support CORS for PUT, DELETE even with XDomainRequest patch.
Now, I want to use something like Reverse proxy so that it will think the request is from same domain. Probably Reverse Proxy
Is it possible in Azure Website? If yes, then how?
Upvotes: 4
Views: 1526
Reputation: 5774
Finally, I found the way of doing it myself :-)
I achieved it using Rewrite Module and ARR.
Here is outline of what I did -
Open Web.config of an app and add following inside <system.webServer> </system.webServer>
<rewrite>
<rules>
<rule name="Route Requests from localhost api to Remote API url" stopProcessing="true">
<match url="^api/(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="https://www.remotedomain.com/api/{R:1}" logRewrittenUrl="true" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
</rules>
<outboundRules>
<rule name="Convert remote API response to localhost API" preCondition="ResponseIsHtmlOrJSON">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://www.remotedomain.com/api/(.*)" />
<action type="Rewrite" value="api/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtmlOrJSON">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^application/json" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
Basically, this will add a rewrite rules (inbound and outbound).
http://localhost/api/{API_PATH}
to https://www.remotedomain.com/api/{API_PATH}
https://www.remotedomain.com/api/
) to dummy API url http://localhost/api
. So the browser will assume the request being sent and response coming back is from local API itself.I blogged the detailed tutorial here : http://www.wrapcode.com/infrastructure/configure-reverse-proxy-with-url-rewrite-and-arr-for-iis/
Upvotes: 5