端口在IISNode上运行的Azure Node.js应用程序中未定义

我有一个使用IISNode运行Node.js应用程序的Azure应用程序服务。 问题是process.env.PORT是未定义的。 我已经读过IISNode使用一个叫做命名pipe道的东西,并且端口信息可能不易读(?),但是在我的情况下,我只能得到未定义的信息。

我尝试部署的项目可以从GitHubfind 。

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

  <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脚本来构build资产并将它们复制到%DEPLOYMENT_TARGET%。

我在这里错过了什么? 任何帮助表示赞赏!

更新

我花了几个小时在多个天,以找出可能是什么原因为什么进程无法启动,因此envvariables未定义。 我在15分钟内把应用程序启动并运行在Heroku上,所以我猜这至less还是个谜(至less对我来说)。

“入门网站”应用程序不会为我部署,看起来像它的许多依赖关系现在被打破。 这就是说,这里是你需要进行Azure应用服务的最小的东西:

 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返回的是什么,它在运行时由平台处理,并保证返回正确的结果。

以下是引擎盖下的情况:

应用服务与NodeJS

Kudu (.scm站点)→Process Explorer→node.exe→属性→环境variables:

Process Explorer