Angular 和 API 在同一域 web.config 中

问题描述 投票:0回答:1

我的应用程序通常有两个域,一个用于应用程序,一个用于 API,如下所示 www.app.com <--- Angular running, web.config needs to rewrite everything to index.html api.app.com <--- my api

现在我想节省一些 ssl 成本并将逻辑更改为这样

www.app.com <--- the same www.app.com/api <--- api now here

我需要如何更改 web.config 才能使此配置生效?我正在为路线规则而苦苦挣扎

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="API Routes" ...>
          <match url="...">
        </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="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
asp.net angular iis
1个回答
0
投票

通过 IIS 管理器,您可以:

  1. API Routes
    部分添加规则。
  2. 选择正则表达式,因此它应该类似于:
    ^api/(.*)
  3. 将条件留空。
  4. 对于操作,选择无操作(除非您想添加一些逻辑)

另外,删除这部分:

<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />

© www.soinside.com 2019 - 2024. All rights reserved.