Express Applications 在 azure 上抛出 500 [英] Express Applications throwing 500 on azure

查看:19
本文介绍了Express Applications 在 azure 上抛出 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 应用程序(网站)仅侦听端口 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;

这篇关于Express Applications 在 azure 上抛出 500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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