Javascript Node.js azure web app可以';我不能进入我的路线
我有以下Javascript Node.js azure web app可以';我不能进入我的路线,javascript,node.js,azure,azure-web-app-service,Javascript,Node.js,Azure,Azure Web App Service,我有以下index.js文件: const express = require('express'); const app = express(); const router = express.Router(); var cors = require('cors'); var http = require('http').Server(app); const fileUpload = require('express-fileupload'); app.use(fileUpload()); c
index.js
文件:
const express = require('express');
const app = express();
const router = express.Router();
var cors = require('cors');
var http = require('http').Server(app);
const fileUpload = require('express-fileupload');
app.use(fileUpload());
const uploadRoute = require('./routes/upload');
app.use(cors());
app.use(uploadRoute(router));
app.use(router);
http.listen(80, function () {
console.log('listening on *:80');
});
以及以下web.config文件:
<?xml version="1.0" encoding="utf-8"?>
<!--
This configuration file is required if iisnode is used to run node processes behind
IIS or IIS Express. For more information, visit:
https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->
<configuration>
<system.webServer>
<!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="index.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not 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 site entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="index.js"/>
</rule>
</rules>
</rewrite>
<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>
<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />
<!--
You can control how Node is hosted within IIS using the following options:
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
* node_env: will be propagated to node as NODE_ENV environment variable
* debuggingEnabled - controls whether the built-in debugger is enabled
See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
-->
<!--<iisnode watchedFiles="web.config;*.js"/>-->
</system.webServer>
</configuration>
然后我尝试使用foreverforever start index.js启动服务器
然后我去我的网站,尝试一条路线,但它只给了我一个错误代码500
谁能告诉我我做错了什么吗?根据我的经验,你可以修改你的index.js
如下,然后再试一次:
const express = require('express');
const app = express();
const router = express.Router();
var cors = require('cors');
var http = require('http').Server(app);
const fileUpload = require('express-fileupload');
app.use(fileUpload());
const uploadRoute = require('./routes/upload');
app.use(cors());
app.use(uploadRoute(router));
app.use(router);
app.set('port', process.env.PORT || 5000);
app.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
此外,对于500错误,您需要启用stdout
和stderr
的日志记录以进行故障排除,并查看日志说明。要启用调试,请执行以下步骤:
如果不存在,则在根文件夹(D:\home\site\wwwroot
)中创建文件iisnode.yml
添加以下行
loggingEnabled:true
日志目录:iisnode
完成后,您可以在D:\home\site\wwwroot\iisnode
中找到日志
有关更多信息,请参阅