[英]nodejs server deployed in Azure is outputting content length
My server.js
looks like this:我的
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);
when i run this locally it outputs what it should:当我在本地运行它时,它会输出它应该的内容:
{"apiBaseUrl":"http://myUrl"}
But when deployed to my Azure instance it behaves slightly different.但是当部署到我的 Azure 实例时,它的行为略有不同。 It also outputs the number of chars:
它还输出字符数:
29
{"apiBaseUrl":"http://myUrl"}
0
Any clue what could cause this issue?任何可能导致此问题的线索?
Edit: i forgot to mention that i am deploying to Azure and have a web.config
in place:编辑:我忘了提到我正在部署到 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>
I have made the following observation:我做了以下观察:
In Azure Portal i turned on Application Insights site extension by clicking the button.在 Azure 门户中,我通过单击按钮打开了 Application Insights 站点扩展。
This automatically created the following settings:这会自动创建以下设置:
The response of my node request is now:我的节点请求的响应现在是:
29
{"apiBaseUrl":"http://myUrl"}
0
After playing around with those new values i found the value causing the issue:在玩弄这些新值后,我发现了导致问题的值:
Changing this to ~1 solved the issue and the response looked as desired:将其更改为 ~1 解决了问题,并且响应看起来符合要求:
response:回复:
{"apiBaseUrl":"http://myUrl"}
I think this is a super strange behavior.我认为这是一种超级奇怪的行为。 I will create a github issue and link it.
我将创建一个 github 问题并链接它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.