Wednesday, June 04, 2014

Using Reserve Proxy for your Single Page App to ovoid CORS

There are couple ways to eliminate CORS, but one of my favourite is to setup reserve proxy server.

Here simplest way how to do it.

1. Install ARR
http://www.iis.net/learn/extensions/installing-application-request-routing-(arr)

2. Enable Proxy
IIS > Select your server > Aplication Request Routing > Server Proxy Setting > Check Enable Proxy

3. Add Url Rewrite inside your site web.config.

<configuration>
<system.webServer>
  <rewrite>
    <rules>
        <rule name="Reverse Proxy to API" stopProcessing="true">
            <match url="^api/(.*)" />
            <action type="Rewrite" url="http://some.api/v1/{R:1}" />
        </rule>
    </rules>
</rewrite>
</system.webServer>
</configuration>

4. Done, now when you request /api in your site, it will automatically forward that to http://come.api/v1/