gpt4 book ai didi

node.js - Express 应用程序在 azure 上扔了 500 个

转载 作者:搜寻专家 更新时间:2023-10-31 22:39:45 24 4
gpt4 key购买 nike

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

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);
});

但是当我将其部署到 azure 时,出现 500 错误。这是我的发现...

  1. 我已经拿了这个advice
  2. 尝试了 server.js、app.js、目录结构等所有可能的组合。

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

最佳答案

Azure Web Apps(网站)仅监听端口 80 和 443。您无法监听端口 8080。

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

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

关于node.js - Express 应用程序在 azure 上扔了 500 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36117795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com