gpt4 book ai didi

node.js - 部署在Azure中的nodejs服务器正在输出内容长度

转载 作者:搜寻专家 更新时间:2023-11-01 00:48:22 24 4
gpt4 key购买 nike

我的server.js看起来像这样:

var http = require('http');

var server = http.createServer(function (request, response) {

const configs = {
apiBaseUrl: 'http://myUrl'
};

const headers = {
'Content-Type': 'application/json'
};
response.writeHead(200, headers);
response.end(JSON.stringify(configs));
});

var port = process.env.PORT || 1337;
server.listen(port);

console.log("Server running at http://localhost:%d", port);

当我在本地运行它时,它会输出它应该输出的内容:

{"apiBaseUrl":"http://myUrl"}

但是当部署到我的 Azure 实例时,它的行为略有不同。它还输出字符数:

29
{"apiBaseUrl":"http://myUrl"}
0

有什么线索可能导致此问题吗?

编辑:我忘了提及我正在部署到 Azure 并有一个 web.config :

<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Get dynamic configs in server environment" stopProcessing="true">
<match url="configs.json" ignoreCase="true"/>
<action type="Redirect" url="currentConfigs.js" redirectType="Permanent" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<handlers>
<add name="iisnode" path="currentConfigs.js" verb="*" modules="iisnode" />
</handlers>
</system.webServer>
</configuration>

最佳答案

我做了以下观察:

在 Azure 门户中,我通过单击按钮打开了 Application Insights 站点扩展

enter image description here

这会自动创建以下设置:

  • APPINSIGHTS_INSTRUMENTATIONKEY
  • APPINSIGHTS_PROFILERFEATURE_VERSION:1.0.0
  • APPINSIGHTS_SNAPSHOTFEATURE_VERSION:1.0.0
  • ApplicationInsightsAgent_EXTENSION_VERSION:~2
  • DiagnosticServices_EXTENSION_VERSION:~3
  • InstrumentationEngine_EXTENSION_VERSION:~1
  • SnapshotDebugger_EXTENSION_VERSION:~1
  • XDT_MicrosoftApplicationInsights_BaseExtensions:~1
  • XDT_MicrosoftApplicationInsights_Mode:推荐

我的 Node 请求的响应现在是:

29
{"apiBaseUrl":"http://myUrl"}
0

在尝试了这些新值之后,我发现了导致问题的值:

  • ApplicationInsightsAgent_EXTENSION_VERSION:~2

将其更改为 ~1 解决了问题,并且响应看起来符合预期:

  • ApplicationInsightsAgent_EXTENSION_VERSION:~1

回复:

{"apiBaseUrl":"http://myUrl"}

我认为这是一个 super 奇怪的行为。我将创建一个 github 问题并链接它。

关于node.js - 部署在Azure中的nodejs服务器正在输出内容长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55694771/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com