简体   繁体   English

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

[英]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:这会自动创建以下设置:

  • APPINSIGHTS_INSTRUMENTATIONKEY APPINSIGHTS_INSTRUMENTATIONKEY
  • APPINSIGHTS_PROFILERFEATURE_VERSION: 1.0.0 APPINSIGHTS_PROFILERFEATURE_VERSION:1.0.0
  • APPINSIGHTS_SNAPSHOTFEATURE_VERSION: 1.0.0 APPINSIGHTS_SNAPSHOTFEATURE_VERSION:1.0.0
  • ApplicationInsightsAgent_EXTENSION_VERSION: ~2 ApplicationInsightsAgent_EXTENSION_VERSION:~2
  • DiagnosticServices_EXTENSION_VERSION: ~3诊断服务_EXTENSION_VERSION:~3
  • InstrumentationEngine_EXTENSION_VERSION: ~1 InstrumentationEngine_EXTENSION_VERSION:~1
  • SnapshotDebugger_EXTENSION_VERSION: ~1 SnapshotDebugger_EXTENSION_VERSION:~1
  • XDT_MicrosoftApplicationInsights_BaseExtensions: ~1 XDT_MicrosoftApplicationInsights_BaseExtensions:~1
  • XDT_MicrosoftApplicationInsights_Mode: recommended XDT_MicrosoftApplicationInsights_Mode:推荐

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:在玩弄这些新值后,我发现了导致问题的值:

  • ApplicationInsightsAgent_EXTENSION_VERSION: ~2 ApplicationInsightsAgent_EXTENSION_VERSION: ~2

Changing this to ~1 solved the issue and the response looked as desired:将其更改为 ~1 解决了问题,并且响应看起来符合要求:

  • ApplicationInsightsAgent_EXTENSION_VERSION: ~1 ApplicationInsightsAgent_EXTENSION_VERSION: ~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.

相关问题 在Heroku上部署的NodeJs服务器 - NodeJs server deployed on Heroku 对部署在 Azure 上的 nodejs 服务器的请求尝试访问 Azure Postgres 灵活数据库时应用服务超时 - Requests to nodejs server deployed on Azure App Service timing out when trying to access Azure Postgres flexible database 如何对部署到Azure WebApp的NodeJS服务器进行微调以应对大量负载 - How to fine-tune NodeJS server deployed to Azure WebApp for massive load 部署到 azure Webapp 的 Nodejs 应用程序无法正常工作 - Nodejs app deployed to azure Webapp not working Nodejs不同的内容长度 - Nodejs different content-length Axios 手动设置 Content-Length,nodeJS - Axios set Content-Length manually, nodeJS 在heroku服务器上部署strapi无法添加内容 - Deployed strapi on heroku server unable to add content 登录部署到 Azure 应用服务的 nodejs 的首选方式 - Preferred way of logging in nodejs deployed to Azure App Services Azure:Web 应用程序 - 从部署的 nodejs 应用程序中列出应用程序设置 - Azure: Web Apps - List Application Settings from deployed nodejs app 部署的 Nodejs 服务在 Azure Web 应用程序上不起作用 - Deployed Nodejs service does not work on Azure Web App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM