【发布时间】:2019-04-16 20:06:11
【问题描述】:
我的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>
【问题讨论】:
-
我使用市场上的“Node JS Empty Web App”启动了一个应用服务,复制并粘贴了您的代码,并收到了预期的仅 JSON 输出,所以我不确定为什么会这样正在为你发生。您如何在 Azure 中运行代码?
-
嗨@MitchStewart我有一个使用iisnode处理程序的web.config。忘了提。谢谢指出!