angularjs - 使用 $http 时,Azure iisnode angularJS 1.x 应用程序无限循环

标签 angularjs azure iisnode

我正在使用 index.html 中的 iisnode/Azure 提供 Angular 1.x 应用程序。路由工作正常,但每当我加载任何进行 $http 资源调用的 view 时,它似乎都会进入无限循环。 api 托管在不同的实例上。我已经测试过在 postman 中点击实例 apiBase/并返回预期的响应。我的 iisnode web.config 如下:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
       <clear />

    <rule name="AngularJS Conditions" stopProcessing="true">
      <match url="(css/.*|images/.*|scripts/.*)" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
      <action type="None" />
    </rule>

    <rule name="AngularJS Wildcard" enabled="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
      <action type="Rewrite" url="index.html" />
    </rule>

  </rules>
</rewrite>

任何帮助都非常有用。对 iisnode/Azure 非常陌生。

最佳答案

实际上,如果您在 Azure Web App 上运行纯 angularJs SPA,则无需配置 web.config 来强制 iisnode 执行您的应用程序。由于 angularJs 应用程序完全是纯 JavaScript 应用程序,并且通过客户端浏览器上的解释器运行。并且您在 IIS 中配置的重写模式可能会破坏 anguarJs 应用程序中的路由事件。

您可以尝试删除 web.config 文件并重新启动 Azure Web Apps。

此外,由于我无法重现您的问题,如果您方便的话,请在 GitHub 或其他任何地方提供问题项目存储库,以便我们检测问题。

更新

如果您使用 angularjs 路由提供程序的 html5mode,这可能是一个常见问题。

请尝试使用以下内容修改您的web.config:

<configuration>
    <system.webServer>
     <rewrite>
      <rules>
        <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>

关于angularjs - 使用 $http 时,Azure iisnode angularJS 1.x 应用程序无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39352579/

相关文章:

c# - Azure 虚拟机没有端点

node.js - 在带有 iisnode 的虚拟目录中运行的 Node.js Express 3 应用程序的 socket.io 路由问题

azure - 来自 Azure B2C 的注册事件

node.js - Windows 7 IIS 7.5 上的 iisnode 抛出 500.19 错误

node.js - 在 iis 上运行 react isomorphic

javascript - Angular 范围内的值变得不确定

javascript - thinkster 上的 Angularfire

javascript - Angular 形式 : how to add class to wrapping div

angularjs - ui-router 动画不适用于嵌套 View

c# - Azure Blob 触发函数存储帐户连接