简体   繁体   English

由于发生内部服务器错误,无法显示该页面。 Node.js 天蓝色

[英]The page cannot be displayed because an internal server error has occurred. Node.js azure

I have node.js application it works locally when I deployed it to Azure App service I get bellow error:我有 node.js 应用程序,当我将它部署到 Azure App 服务时,它可以在本地运行,但出现以下错误:

The page cannot be displayed because an internal server error has occurred.由于发生内部服务器错误,无法显示该页面。

bellow is my server.js code:下面是我的 server.js 代码:

 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const express = require("express"); const bodyParser = require("body-parser"); const cookieParser = require("cookie-parser"); const errorhandler = require("errorhandler"); const morgan = require("morgan"); const cors = require("cors"); const router_1 = require("./routes/router"); const bunyan_logger_1 = require("./lib/loggers/bunyan.logger"); require("reflect-metadata"); //const database = require('./data/dbprovider/dbmssql'); class Server { constructor() { this.port = process.env.PORT || 3000; this.logger = new bunyan_logger_1.bunyanLogger(); this.app = express(); this.initExpressMiddleWare(); this.initCustomMiddleware(); this.initRoutes(); this.start(); } start() { this.app.listen(this.port, (err) => { if (err) { this.logger.StartLogger().error('In Server.TS start see details: ' + err); } else { console.log('Listening on http://localhost:%d', process.env.NODE_ENV, this.port); } }); } initExpressMiddleWare() { this.app.use(express.static(__dirname + '/public')); this.app.use(morgan('dev')); this.app.use(bodyParser.urlencoded({ extended: true })); this.app.use(bodyParser.json()); this.app.use(errorhandler()); this.app.use(cookieParser()); this.app.use(cors()); // Add headers this.app.use(function (req, res, next) { // Website you wish to allow to connect const allowOrigin = ['https://senserver4.azurewebsites.net','http://localhost:3000']; const origin = req.headers.origin; if (allowOrigin.indexOf(origin) > -1) { res.setHeader('Access-Control-Allow-Origin', origin); } // Request methods you wish to allow res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); // Request headers you wish to allow res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); // Set to true if you need the website to include cookies in the requests sent // to the API (eg in case you use sessions) res.setHeader('Access-Control-Allow-Credentials', true); // Pass to next layer of middleware next(); }); //this.app.use(csrf({ cookie: true })); // this.app.use((req: { csrfToken: () => void; }, res: { locals: { _csrf: any; }; cookie: (arg0: string, arg1: any) => void; }, next: () => void) => { // let csrfToken = req.csrfToken(); // res.locals._csrf = csrfToken; // res.cookie('XSRF-TOKEN', csrfToken); // next(); // }); process.on('uncaughtException', (err) => { if (err) console.log(err, err.stack); }); } initCustomMiddleware() { if (process.platform === "win32") { require("readline").createInterface({ input: process.stdin, output: process.stdout }).on("SIGINT", () => { process.exit(1); }); } process.on('SIGINT', () => { process.exit(1); }); } initRoutes() { (new router_1.Router()).load(this.app, './controllers'); } } let server = new Server(); //# sourceMappingURL=server.js.map

I have created web.config file in root of my project below is the web.config code:我在我的项目的根目录中创建了 web.config 文件,下面是 web.config 代码:

<?xml version="1.0" encoding="utf-8"?>

<configuration>
<appSettings>

</appSettings>
<system.webServer>
<staticContent>
  <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>

<modules runAllManagedModulesForAllRequests="false" />

<iisnode watchedFiles="web.config;*.js;routes\*.js;views\*.pug"/>

<handlers>
  <add name="iisnode" path="app.js" verb="*" modules="iisnode" />

</handlers>

<security>
  <requestFiltering>
    <hiddenSegments>
      <remove segment="bin" />
    </hiddenSegments>
  </requestFiltering>
</security>

<rewrite>
  <rules>
    <clear />

    <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="^server.js\/debug[\/]?" />
    </rule>

    <rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="iisnode.+" negate="true" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
      <action type="Rewrite" url="app.js" />
    </rule>
  </rules>
</rewrite>
</system.webServer>

I have added my server.js in path mapping, but I could not resolve the issue.我已经在路径映射中添加了我的 server.js,但我无法解决这个问题。

Error I get in console:我在控制台中遇到的错误:

Tue Jan 14 2020 16:01:06 GMT+0000 (Coordinated Universal Time): Application has thrown an uncaught exception and is terminated:
D:\home\site\wwwroot\public\data\repos\Agent.repo.js:13
async getAllAgent() {
      ^^^^^^^^^^^
SyntaxError: Unexpected identifier
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (D:\home\site\wwwroot\public\controllers\api\agents\agent.controller.js:3:22)
at Module._compile (module.js:570:32)     

This error is the common description of IIS server 500 error.此错误是IIS 服务器500 错误的常见描述。 It will be hard to find the root cause of the question by only the general description.仅通过一般描述很难找到问题的根本原因。

Please try below code of web.config to show the details that might helps you and don't comment your previous code.请尝试下面的 web.config 代码以显示可能对您有帮助的详细信息,并且不要评论您以前的代码。

<configuration>
    <system.webServer>
        <httpErrors errorMode="Detailed" />
        <asp scriptErrorSentToBrowser="true"/>
    </system.webServer>
    <system.web>
        <customErrors mode="Off"/>
        <compilation debug="true"/>
    </system.web>
</configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM