node.js - 具有虚拟目录的 Azure 应用服务 NodeJ

标签 node.js angular azure web-config

我有一个基于 Angular7 构建的网站,并在 Azure 应用服务上部署了服务器端渲染。我必须添加一个 web.config 文件才能使 server.js 运行。 这是 web.config 文件

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>    
    <webSocket enabled="false" />
    <handlers>    
      <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^server.js\/debug[\/]?" />
        </rule>
        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="server.js"/>
        </rule>
      </rules>
    </rewrite>    
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>
    <httpErrors existingResponse="PassThrough" />
    </system.webServer>
    </configuration>

此网站已部署到 mysite.com,一切正常。

我现在需要创建一个虚拟目录 mysite.com/app 来保存不同的应用程序(在旧的 AngularJS 上)。如果没有服务器端渲染,我只需在 Azure 门户上创建虚拟目录,一切正常。由于服务器端和“重定向”到 server.js,虚拟目录不再工作。 web.config 文件中是否有任何规则可以忽略/app 的请求,而不是运行 nodejs 服务器?

最佳答案

我在另一个 question 上得到了回复(归功于 dana)所以我刚刚添加了规则

<rule name="ignore app application" stopProcessing="true">
    <match url="^app" />
    <action type="None" />
</rule>

在其他规则之前。这样,如果输入的网址是 mysite.com/app, Node 服务器将不会被“激活”,并且虚拟目录将按预期工作。

关于node.js - 具有虚拟目录的 Azure 应用服务 NodeJ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54445453/

相关文章:

azure - 使用 python sdk v2 在 azureml 中进行模型漂移和数据漂移

azure - Bot 服务迁移 - 'failed to find any Azure subscriptions for the current user.' 错误消息

node.js - 类验证器 @ValidateIf() 无法正常工作

node.js - 在云端使用 NodeJS 和 RavenDB (appharbor)

angular - 以 Angular react 形式动态设置文本区域禁用

angular - 将样式传递给组件的最佳方式

azure - 当存储帐户尝试使用私有(private)终结点访问 Key Vault 中的客户托管 key (使用 Terraform)时,出现 "KeyVaultAuthenticationFailure"

javascript - 如何在特定路径前缀上挂载 app.get() 路由

mysql - Sequelize 4 - eagger 加载时属于多对多插入问题

html - 如何在 ionic v4 的 item-native div 中编辑 "item-inner"类?