1

I have an application using Angular and node.js (running on IIS 7.5) for the UI, and then a .NET Web API for all the endpoint calls.

Angular routing is working as expected, and API routing is working as expected...when running the API through Visual Studio/IIS Express and ng serve to fire up the UI. Of course, they're running on two separate ports.

The goal is to deploy to a single IIS Web Site and, unfortunately, a single Application Pool.

Given the URL of http://www.mycoolapplication.com for the UI and http://www.mycoolapplication.com/api for the API, how to I get Angular to ignore routing for anything matching api and all of api's children?

I'm going through the Routes module, and would love to be able to add something to a path object, but there doesn't appear to be anything to accomplish excluding something from the Angular routing table.

1 Answer 1

2

Put this web.config in your frontend app (the folder with index.html). It will handle all requests except api/*.

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="API Rule" stopProcessing="true">
          <match url="^(api)(.*)$" />
          <action type="None" />
        </rule>
        <rule name="Angular" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
Sign up to request clarification or add additional context in comments.

1 Comment

Worked perfectly, @maxim Thanks for the help. For some reason, I didn't think the web.config would come into play for the routing in this scenario. The configuration must be processing the rewrite rules in order since the API Rule is "before" the Angular rule, which I already had in my web.config.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.