如何在Azure App Service上调试Node.js App-获取HTTP状态码500 [英] How to debug nodejs app on azure app service - Getting http status code 500
问题描述
我是Node.js中的新手.我有一个基本的nodejs应用程序,可以在具有nodejs v10.15.0和npm v6.9.0的Windows PC上正常运行,但是当我将其部署到节点版本为10.15.2的Windows平台上的Azure App Service时,得到 500内部服务器错误. 我已经尝试使用web.config中的iisnode loggingEnabled标志进行调试,并且可以看到正在记录以下消息.我不确定它的警告或错误是否导致500.
I am a newbie in nodejs. I have a basic nodejs app which runs fine on my windows PC with nodejs v10.15.0 and npm v6.9.0 but when I deploy it to Azure App Service on windows platform with node version 10.15.2 , I get 500 internal server error. I have tried debugging using iisnode loggingEnabled flag in web.config and I can see following message being logged. I am not sure if its warning or error which is causing 500.
(节点:25936)[DEP0005] DeprecationWarning:由于安全性和可用性问题,不建议使用Buffer().请改用Buffer.alloc(),Buffer.allocUnsafe()或Buffer.from()方法. "
"(node:25936) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead."
配置:
{
"name": "redis_test_app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\"
&& exit 1",
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"applicationinsights": "^1.4.0",
"body-parser": "^1.18.3",
"express": "^4.16.3",
"livereload": "^0.7.0",
"redis": "^2.8.0"
}
}
web.config
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 flushResponse="true" loggingEnabled="true" logDirectory="iisnode" watchedFiles="web.config;*.js"/>
</system.webServer>
</configuration>
app.js
const appInsights = require("applicationinsights");
appInsights.setup("")
.setAutoDependencyCorrelation(true)
.setAutoCollectRequests(true)
.setAutoCollectPerformance(true)
.setAutoCollectExceptions(true)
.setAutoCollectDependencies(true)
.setAutoCollectConsole(true)
.setUseDiskRetryCaching(true)
.start();
var redis = require('redis');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var client = redis.createClient(xxxx, 'gfkdhggk865487766jggdfgdf', {
auth_pass: 'passcode',
tls: { servername: 'xxxxxxxx' }
});
var config = require('./server.config');
var port = config.port;
// allow cross origin
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use('/', require('./src/routes')());
app.listen(port, function () {
console.log(`Maintenance server listening on port ${port}!`)
});
// check if the client is connected to redis
client.on('connect', function () {
console.log('Connected to Redis');
});
推荐答案
You can enable node.js application level log to see the error message.
您在此处粘贴的日志仅是警告,不是错误.你可以找到 代码中新的Buffer()方法,并用新的方法替换它们,以免发生这种情况.
The log you pasted here is only a warning, not an error. You can find the new Buffer() methods in your codes and replace them with a new one to avoid this.
确保将项目部署到Azure时已更改侦听端口.您应该在app.js文件中使用app.listen(process.env.PORT);
.
Make sure you have changed the listen port when you deploy your project to Azure. You should use app.listen(process.env.PORT);
in your app.js file.
这是一个指南有关
Here is a guide regarding deploying nodejs app to azure for your reference.
这篇关于如何在Azure App Service上调试Node.js App-获取HTTP状态码500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!