简体   繁体   English

process.env.port变量上的Node.js和MS Azure

[英]Node.js and MS Azure on process.env.port variable

consider the following Node.js code: 考虑以下Node.js代码:

var http = require('http');
var port = process.env.port || 1337;
http.createServer(function (req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Hello World\n');
}).listen(port);

It does not work in Microsoft Azure, because of string value in process.env.port variable (for example: \\.\\pipe\\e289ed7e-b57b-46bb-8bba-ad8cd1f1529cf). 它在Microsoft Azure中不起作用,因为process.env.port变量中的字符串值(例如:\\。\\ pipe \\ e289ed7e-b57b-46bb-8bba-ad8cd1f1529cf)。 Why is it happening? 为什么会这样?

The only thing should be done is to have a proper web.config file, for handling the named pipe port in Microsoft Azure. 唯一应该做的就是拥有一个合适的web.config文件,用于处理Microsoft Azure中的命名管道端口。 The simplest content for this file can be: 此文件最简单的内容可以是:

<configuration>
<system.webServer>
      <handlers>
        <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
      </handlers>
      <rewrite>
        <rules>
          <rule name="DynamicContent">
            <match url="/*" />
            <action type="Rewrite" url="server.js"/>
          </rule>
        </rules>
      </rewrite>
</system.webServer>
</configuration> 

if your initial NodeJS file is app.js , replace the server.js strings in above content with it! 如果你的初始NodeJS文件是app.js ,用它替换上面内容中的server.js字符串!

Should be case sensitive. 应该区分大小写。 Try: 尝试:

process.env.PORT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM