node.js - 部署在 Azure 中的 nodejs 服务器正在输出内容长度
问题描述
我的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 站点扩展。
这会自动创建以下设置:
- APPINSIGHTS_INSTRUMENTATIONKEY
- APPINSIGHTS_PROFILERFEATURE_VERSION:1.0.0
- APPINSIGHTS_SNAPSHOTFEATURE_VERSION:1.0.0
- ApplicationInsightsAgent_EXTENSION_VERSION:~2
- 诊断服务_EXTENSION_VERSION:~3
- InstrumentationEngine_EXTENSION_VERSION:~1
- SnapshotDebugger_EXTENSION_VERSION:~1
- XDT_MicrosoftApplicationInsights_BaseExtensions:~1
- XDT_MicrosoftApplicationInsights_Mode:推荐
我的节点请求的响应现在是:
29
{"apiBaseUrl":"http://myUrl"}
0
在玩弄了这些新值之后,我发现了导致问题的值:
- ApplicationInsightsAgent_EXTENSION_VERSION:~2
将其更改为 ~1 解决了该问题,并且响应看起来符合预期:
- ApplicationInsightsAgent_EXTENSION_VERSION:~1
回复:
{"apiBaseUrl":"http://myUrl"}
我认为这是一种超级奇怪的行为。我将创建一个 github 问题并链接它。
推荐阅读
- python - 使用python在excel中查找缺少的列标题
- java - 如何将spring项目作为jar lib导出到另一个项目并使用它的功能?
- google-chrome - 超出最大 IPC 消息大小
- html - 带溢出的按钮设计
- python - 使用 fb ad Insights api 获取广告优化的转化
- python - 使用不带 FilePrefix 的 vtkVolume16Reader
- sidekiq - 如何在公共 0.0.0.0 上启动 Sidekiq Web UI?
- java - Servlet 向 jsp 传递数据
- html - 表单按钮 CSS 样式仅适用于检查
- java - 如何从 xamarin android 中的 AutocompletePredictionBufferResponse 获取 AutocompletePredictionBuffer