快速应用程序将500丢到天蓝色 [英] Express Applications throwing 500 on azure

查看:58
本文介绍了快速应用程序将500丢到天蓝色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码可在本地完美运行...

The following code runs perfectly locally...

var express = require('express');
var app = express();

app.get('/', function (req, res) {
    res.send("Hello World");
});

var port = 8080;

app.listen(port, function () {
    console.log('Server started and is listening on port ' + port);
});

但是当我将其部署到天蓝色时,会出现500错误.这是我的发现...

But when i deploy it to azure I get a 500 error. Here is my findings...

  1. 我已采纳了此建议
  2. 尝试过server.js,app.js,目录结构等的所有可能组合.

正在从本地git存储库中部署代码.

The code is being deployed from a local git repo.

推荐答案

Azure Web Apps(网站)仅在端口80和443上侦听.您无法在端口8080上监听.

Azure Web Apps (web sites) listen on ports 80 and 443 only. You can not listen on port 8080.

您需要在端口process.env.PORT上监听.通过将端口代码调整为类似以下内容,您可以轻松地在本地和Azure中运行:

You'll need to listen on port process.env.PORT. And you can easily run both locally and in Azure by tweaking your port code to something like:

var port = process.env.PORT || 8080;

这篇关于快速应用程序将500丢到天蓝色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆