我有一个使用 IISNode 运行 Node.js 应用程序的 Azure 应用服务。问题是process.env.PORT
未定义。我读过 IISNode 使用一个叫做命名管道并且端口信息可能不容易读取(?),但就我而言,我只是未定义。
我尝试部署的项目可以从GitHub https://github.com/ttamminen/NodeJS-StarterSiteTemplate.
我确实定义了一个 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 脚本,它将构建资产并将它们复制到%DEPLOYMENT_TARGET%。
我在这里缺少什么?任何帮助表示赞赏!
Update
我花了好几天的时间来找出进程无法启动并因此环境变量未定义的原因。我在 15 分钟内就在 Heroku 上安装并运行了该应用程序,所以我想这仍然是个谜(至少对我来说)。
“Starter Site”应用程序没有为我部署,看起来它的许多依赖项现在都已损坏。话虽如此,以下是使用 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
返回,它由平台在运行时处理,并保证返回正确的东西。
以下是幕后的情况:
Kudu(.scm站点)→进程资源管理器→node.exe→属性→环境变量:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)