首页 > 解决方案 > Node Express 在 Azure 应用服务中发送切片响应

问题描述

我有一个在 Azure 应用服务中运行的快速应用程序。我遇到了这种奇怪的行为,我在日志中看到服务器发送了 39.1 MB 的响应。但是客户端只能得到一部分响应。

例如,如果服务器响应以下内容,

[
  {
    id: 1,
    name: 'john doe',
    address: 'park street'
  },
  {
    id: 2,
    name: 'john simon',
    address: 'ranger avenue'
  },
]

在客户端,我收到以下信息,

[
  {
    id: 1,
    name: 'john doe',
    address: 'park street'
  },
  {
    id: 2,
    name: 'john simon',
   

如您所见,响应在中间被切分,不包括以下内容。

    address: 'ranger avenue'
  },
]

当我使用 cURL 命令获取响应时,我可以看到它正在等待我的响应完全完成,但它从来没有完成,我在终端中看到了这个。

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
 30 39.1M   30 12.0M    0     0  46706      0  0:14:39  0:04:29  0:10:10     0
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54

我猜在客户端和我的快速服务器之间,Azure App Service 正在干预我无法弄清楚的响应数据。

这是我的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>
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^server.js\/debug[\/]?" />
        </rule>

        <rule name="StaticContent">
          <action type="Rewrite" url="public{PATH_INFO}"/>
        </rule>

        <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>

任何帮助深表感谢。谢谢!

编辑:

这种行为是随机的,有时我会在客户端得到完整的响应。我注意到这通常发生在大型响应中。如果是 1 MB,它不会发生(至少在我测试时)。

标签: node.jsazureexpressazure-web-app-service

解决方案


推荐阅读