Azure 中的节点 Web 应用程序为空白
node web app in azure is blank
我是 node 和 express 的新手,但是当我在 windows azure 中托管我的 node web 应用程序时遇到了问题,顺便说一句,它在本地主机上完全正常。我只是得到一个空白的白色屏幕。
这是我的:
server.js
var root = require('root');
var github = require('github-auth');
var express = require('express');
var path = require('path');
// var app = root();
var app = express();
var gh = github('clientid', 'clientsecret, {
organization: 'my-org',
team: 'my-team',
autologin: true // This automatically redirects you to github to login
});
app.get('/login', gh.login);
app.use(express.static(__dirname + '/'));
app.all('*', gh.authenticate);
app.all('*', function(req, res, next) {
if (!req.github) return res.sendFile(__dirname + '/login.html');
if (!req.github.authenticated) res.sendFile(path.join(__dirname+'/kickout.html'));
next();
});
app.get('/main',function(req,res){
res.sendFile(path.join(__dirname+'/main.html'));
});
app.get('/about',function(req,res){
res.sendFile('/kickout.html');
});
app.listen(3000);
console.log("Running at Port 3000");
通过 Azure Web 应用程序托管 Node.js 应用程序时,您需要修改端口初始化,如下面的简化示例所示:
var http = require('http'),
port = process.env.PORT || 1337;
http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(port);
在本地 运行 时,将使用文字端口(例如上面的 1337
),但是当在 Azure 中 运行 时,端口将分配给 process.env.port
托管平台,将被使用。您可以找到有关部署 Node.js 应用 here. When running in a WebApp, a technology called IIS Node is used to run your Node app. More details on that can be found here.
的完整演练
Node.js 应用程序 运行ning 在 Azure Web 应用服务上,托管在 IIS 上通过 IISNode 处理的映射,它提供 Named Pipe
来接收传入请求,而不是 TCP 端口就像你在本地 运行ning 时使用的那样。
此 Named Pipe
已在 Node.js 运行 时间在 Azure Web Apps 上定义为 port
。您可以在您的应用 link 中定义 port
: process.env.PORT || 3000
,您的应用可以在 Azure 或本地 运行
然后你可以查看你的根目录下是否有一个文件web.config
,它是你应用程序的IIS配置。它应该有类似的内容:
<configuration>
<system.webServer>
<handlers>
<!-- indicates that the app.js file is a node.js application to be handled by the iisnode module -->
<add name="iisnode" path="server.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="^server.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">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
<!-- You can control how Node is hosted within IIS using the following options -->
<!--<iisnode
node_env="%node_env%"
nodeProcessCommandLine=""%programfiles%\nodejs\node.exe""
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"/>
</system.webServer>
</configuration>
我是 node 和 express 的新手,但是当我在 windows azure 中托管我的 node web 应用程序时遇到了问题,顺便说一句,它在本地主机上完全正常。我只是得到一个空白的白色屏幕。
这是我的: server.js
var root = require('root');
var github = require('github-auth');
var express = require('express');
var path = require('path');
// var app = root();
var app = express();
var gh = github('clientid', 'clientsecret, {
organization: 'my-org',
team: 'my-team',
autologin: true // This automatically redirects you to github to login
});
app.get('/login', gh.login);
app.use(express.static(__dirname + '/'));
app.all('*', gh.authenticate);
app.all('*', function(req, res, next) {
if (!req.github) return res.sendFile(__dirname + '/login.html');
if (!req.github.authenticated) res.sendFile(path.join(__dirname+'/kickout.html'));
next();
});
app.get('/main',function(req,res){
res.sendFile(path.join(__dirname+'/main.html'));
});
app.get('/about',function(req,res){
res.sendFile('/kickout.html');
});
app.listen(3000);
console.log("Running at Port 3000");
通过 Azure Web 应用程序托管 Node.js 应用程序时,您需要修改端口初始化,如下面的简化示例所示:
var http = require('http'),
port = process.env.PORT || 1337;
http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(port);
在本地 运行 时,将使用文字端口(例如上面的 1337
),但是当在 Azure 中 运行 时,端口将分配给 process.env.port
托管平台,将被使用。您可以找到有关部署 Node.js 应用 here. When running in a WebApp, a technology called IIS Node is used to run your Node app. More details on that can be found here.
Node.js 应用程序 运行ning 在 Azure Web 应用服务上,托管在 IIS 上通过 IISNode 处理的映射,它提供 Named Pipe
来接收传入请求,而不是 TCP 端口就像你在本地 运行ning 时使用的那样。
此 Named Pipe
已在 Node.js 运行 时间在 Azure Web Apps 上定义为 port
。您可以在您的应用 link 中定义 port
: process.env.PORT || 3000
,您的应用可以在 Azure 或本地 运行
然后你可以查看你的根目录下是否有一个文件web.config
,它是你应用程序的IIS配置。它应该有类似的内容:
<configuration>
<system.webServer>
<handlers>
<!-- indicates that the app.js file is a node.js application to be handled by the iisnode module -->
<add name="iisnode" path="server.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="^server.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">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
<!-- You can control how Node is hosted within IIS using the following options -->
<!--<iisnode
node_env="%node_env%"
nodeProcessCommandLine=""%programfiles%\nodejs\node.exe""
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"/>
</system.webServer>
</configuration>