Web应用程序时出错

Web应用程序时出错

本文介绍了在Azure上发布Node.js Web应用程序时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我在Visual Studio中使用express框架创建了一个nodejs Web应用程序.该代码在localhost中运行完美.它显示了一个简单的表单,该表单接受用户输入并显示他/她在表单中输入的所有内容.所以一件事情接连发生.

I created a nodejs web application using express framework in visual studio. The code ran perfect in localhost. It shows a simple form that takes user input and displays whatever he/she entered in the form. So one thing happens after another.

当我在Azure上发布该应用程序时,它始终显示该页面无法显示,因为发生了内部服务器错误."

When i published the app on azure it kept showing "the page cannot be displayed because an internal server error has occurred."

我试图在同一应用程序,新应用程序上重新发布,而在其他应用程序上则没有.创建了一个新项目,重新启动了我的应用程序,所有人可能想到的一切.

I tried to republish on same app, on new app and what not. Created new project, restarted my app and everything one can possibly think of. 

最后我尝试了一件事.我更改了解决问题的代码.尽管是过去1天我一直在努力解决的错误,但我仍然不明白为什么更改代码可以解决问题,因为两个版本的代码都表示相同 东西.

At last i tried one thing. I changed the code which solved the problem. Although it the error i had been struggling with for the past 1 day, I still couldn't understand why changing the code solved the problem because they both versions of code say the same thing.

所以我想知道为什么在Azure上发布后版本1不能运行但版本2可以运行的原因.

So I would like to know the reason why version 1 wasn't working but version 2 is working after publishing on Azure. 

P.s-两种版本都可以在localhost上正常运行.两个代码截图(更改前后)都已附加.

P.s- both versions work well on localhost. Both code screenshots (before and after changed) have been attached.

版本1的代码-

var http = require("http");
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({ extended: true });

// Running Server Details.
var server = app.listen(1337,function () {
    var host = server.address().address
    var port = server.address().port
    console.log("Example app listening at %s:%s Port", host, port)
});
app.get('/', function (req, res) {
    var html = '';
    html += "<body>";
    html += "<form action='/thank'  method='post' name='form1'><br>";
    html += "Name: <input type= 'text' name='name'><br>";
    html += "Email:<input type='text' name='email'><br>";
    html += "address:<input type='text' name='address'><br>";
    html += "Mobile number:<input type='text' name='mobilno'><br>";
    html += "<input type='submit' value='submit'><br>";
    html += "<INPUT type='reset'  value='reset'>";
    html += "</form>";
    html += "</body>";
    res.send(html);
});
app.post('/thank', urlencodedParser, function (req, res) {
    var reply = '';
    reply += "Your name is" + req.body.name;
    reply += "Your E-mail id is" + req.body.email;
    reply += "Your address is" + req.body.address;
    reply += "Your mobile number is" + req.body.mobilno;
    res.send(reply);
});

代码版本2(此代码在运行时会发生变化)-

var http = require("http");
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({ extended: true });
var port = process.env.PORT || 1337;

// Running Server Details.
var server = app.listen(port,function () {
    var host = server.address().address
    //var port = server.address().port
    console.log("Example app listening at %s:%s Port", host, port)
});
app.get('/', function (req, res) {
    var html = '';
    html += "<body>";
    html += "<form action='/thank'  method='post' name='form1'><br>";
    html += "Name: <input type= 'text' name='name'><br>";
    html += "Email:<input type='text' name='email'><br>";
    html += "address:<input type='text' name='address'><br>";
    html += "Mobile number:<input type='text' name='mobilno'><br>";
    html += "<input type='submit' value='submit'><br>";
    html += "<INPUT type='reset'  value='reset'>";
    html += "</form>";
    html += "</body>";
    res.send(html);
});
app.post('/thank', urlencodedParser, function (req, res) {
    var reply = '';
    reply += "Your name is" + req.body.name;
    reply += "Your E-mail id is" + req.body.email;
    reply += "Your address is" + req.body.address;
    reply += "Your mobile number is" + req.body.mobilno;
    res.send(reply);
});

推荐答案

这是一个500错误,表示它来自应用程序.您可以启用诊断日志记录并通过门户为您的应用程序打开失败的请求跟踪,以检查完整的错误详细信息.另外,请确保您的应用程序在最新的Node& Visual Studio版本.

The is a 500 error which means it coming from the application. You can enable diagnostics logging and turn on failed request tracing for your apps through the portal to check the complete error details. Also, please make sure your app is running on the latest Node & Visual Studio versions.


这篇关于在Azure上发布Node.js Web应用程序时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 01:25