gpt4 book ai didi

javascript - Node.js azure Web 应用程序无法访问我的路线

转载 作者:行者123 更新时间:2023-11-30 20:11:12 27 4
gpt4 key购买 nike

我有以下 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>

现在我将其添加到我的服务器中,使其看起来像这样:

enter image description here

然后我尝试使用永远forever 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 错误,您需要启用 stdoutstderr 日志记录以进行故障排除并查看日志内容。要启用调试,请按照以下步骤操作:

  1. 如果不存在,请在根文件夹 (D:\home\site\wwwroot) 中创建文件 iisnode.yml

  2. 向其中添加以下行。

    启用日志记录:true日志目录:iisnode

完成后,您可以在D:\home\site\wwwroot\iisnode中找到日志。

更多信息请参阅doc .

关于javascript - Node.js azure Web 应用程序无法访问我的路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52402385/

27 4 0
文章推荐: c# - 处理器线程 C#
文章推荐: c - C 文件的问题
文章推荐: c# - Lambda 委托(delegate)决议
文章推荐: c++ - 指针地址
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com