Я новичок в nodejs.У меня есть базовое приложение nodejs, которое отлично работает на моем компьютере с Windows с nodejs v10.15.0 и npm v6.9.0, но при развертывании его в службе приложений Azure на платформе Windows с версией узла 10.15.2 я получаю 500 внутренний серверошибка .Я попытался отладить с помощью флага iisnode loggingEnabled в web.config, и я вижу, что следующее сообщение регистрируется.Я не уверен, что его предупреждение или ошибка вызывают 500.
"(узел: 25936) [DEP0005] DeprecationWarning: Buffer () устарел из-за проблем с безопасностью и удобством использования. Используйте буферВместо этого используются методы .alloc (), Buffer.allocUnsafe () или Buffer.from (). "
Конфиг:
{
"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
<?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');
});