在IISNode上运行的Azure Node.js应用程序中未定义端口 [英] Port being undefined in the Azure Node.js application running on IISNode

查看:105
本文介绍了在IISNode上运行的Azure Node.js应用程序中未定义端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用IISNode运行Node.js应用程序的Azure应用服务.问题是process.env.PORT是未定义的.我已经读到IISNode使用了一个名为命名管道的东西,并且端口信息可能不容易阅读(?),但就我而言,我只能得到未定义的信息.

I have an Azure App Service running Node.js application using IISNode. The problem is that process.env.PORT is undefined. I have read that IISNode uses a thing called named pipes and that the port information might not be easily readable (?), but in my case I only get undefined.

我尝试部署的项目可以在 GitHub 中找到.

The project I try to deploy can be found from GitHub.

我确实定义了一个Web.config文件,它看起来像这样:

I do have a Web.config file defined and it looks like this:

    <handlers>
        <!-- indicates that the app.js file is a node.js application to be handled by the iisnode module -->
        <add name="iisnode" path="index.js" verb="*" modules="iisnode" />
    </handlers>

    <rewrite>
        <rules>
            <!-- Don't interfere with requests for node-inspector debugging -->
            <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
                <match url="^index.js\/debug[\/]?" />
            </rule>

            <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
            <rule name="StaticContent">
                <action type="Rewrite" url="public{REQUEST_URI}" />
            </rule>

            <!-- All other URLs are mapped to the Node.js application entry point -->
            <rule name="DynamicContent">
                <match url="/*" />
                <action type="Rewrite" url="index.js" />
            </rule>
        </rules>
    </rewrite>

    <!-- You can control how Node is hosted within IIS using the following options -->
                <!--<iisnode      
                  node_env="%node_env%"
                  nodeProcessCountPerApplication="1"
                  maxConcurrentRequestsPerProcess="1024"
                  maxNamedPipeConnectionRetry="3"
                  namedPipeConnectionRetryDelay="2000"      
                  maxNamedPipeConnectionPoolSize="512"
                  maxNamedPipePooledConnectionAge="30000"
                  asyncCompletionThreadCount="0"
                  initialRequestBufferSize="4096"
                  maxRequestBufferSize="65536"
                  watchedFiles="*.js"
                  uncFileChangesPollingInterval="5000"      
                  gracefulShutdownTimeout="60000"
                  loggingEnabled="true"
                  logDirectoryNameSuffix="logs"
                  debuggingEnabled="true"
                  debuggerPortRange="5058-6058"
                  debuggerPathSegment="debug"
                  maxLogFileSizeInKB="128"
                  appendToExistingLog="false"
                  logFileFlushInterval="5000"
                  devErrorsEnabled="true"
                  flushResponse="false"      
                  enableXFF="false"
                  promoteServerVars=""
                 />-->
    <iisnode watchedFiles="*.js;node_modules\*;routes\*.js;views\*.jade;views\account\*.jade;iisnode.yml" />
</system.webServer>

我写了一个Kudu脚本,它将构建资产并将其复制到%DEPLOYMENT_TARGET%.

I have written a Kudu scripts that will build the assets and copy them to %DEPLOYMENT_TARGET%.

我在这里想念的是什么?感谢您的帮助!

What is it that I am missing here? Any help is appreciated!

我花了好几天的时间来找出导致进程无法启动并因此env变量未定义的原因.我在15分钟内在Heroku上启动并运行了该应用程序,所以我认为这仍然是个谜(至少对我而言).

I spent hours on multiple days to find out what could be the cause why the process doesn't start and therefore env variables are undefined. I got the app up and running on Heroku in 15 minutes, so I guess this stays mystery (for me at least).

推荐答案

"Starter Site"应用程序无法为我部署,它的许多依赖项现在都已损坏.话虽如此,这是开始使用Azure App Service所需的最少内容:

The "Starter Site" app does not deploy for me, looks like many of its dependencies are now broken. That being said, here's the minimal stuff you need to get going on Azure App Service:

var http = require('http');

function onRequest(request, response) {
    response.writeHead(200, {
        'Content-type': 'text-plain'
    });
    response.write('Hello from Node.');
    response.end();
}

// provess.env.PORT will expand to the name pipe value on App Service
// request --> Frontends (ARR) --> Web Worker (IIS) --> iisnode --> 
//    --named-pipe--> node.exe server.js

http.createServer(onRequest).listen(process.env.PORT || 3000);
console.log('Listening for requests on port ' + (process.env.PORT || 3000));

您不必担心process.env.PORT返回什么,它由平台在运行时处理,并且可以保证返回正确的内容.

You don't have to worry about what process.env.PORT returns, it's handled by the platform at runtime and it's guaranteed to return the right thing.

下面是事物的外观:

Kudu (.scm网站)→流程浏览器→ node.exe→属性→环境变量:

Kudu (.scm site) → Process Explorer → node.exe → Properties → Environment variables:

这篇关于在IISNode上运行的Azure Node.js应用程序中未定义端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆