【问题标题】:App Crashing when Deploying Heroku (Code h10)部署 Heroku 时应用程序崩溃(代码 h10)
【发布时间】:2019-11-02 05:04:05
【问题描述】:

我正在尝试将我的应用程序部署到 Heroku,但我一直在崩溃。我使用我的 CLI 打开我的应用程序,但它仍然崩溃,我什至在 Keroku 仪表板上部署分支,它仍然崩溃。我想知道我的 app.js 或 packjson 有什么问题

这是我得到的错误:

2019-06-19T12:32:14.679424+00:00 heroku[路由器]: at=error code=H10 desc="应用程序崩溃" 方法=GET 路径="/" host=guarded-island-18465.herokuapp.com request_id=66a60c63-3bad-47ad-8255-85f56798df95fwd="97.99.40.66" dyno= 连接=服务=状态=503字节= 协议=https2019-06-19T12:32:15.283697+00:00 heroku[路由器]: at=错误代码=H10 desc="App 崩溃" 方法=GET path="/favicon.ico" host=guarded-island-18465.herokuapp.com request_id=888cb97b-7aaf-4e0b-97c5-d01432d188a6 fwd="97.99.40.66" dyno=连接=服务=状态=503字节=协议=https

{
  "name": "newburger2",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js"   
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/jnperk1234/neweatdaburger.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/jnperk1234/neweatdaburger/issues"
  },
  "homepage": "https://github.com/jnperk1234/neweatdaburger#readme",
  "dependencies": {
    "body-parser": "^1.19.0",
    "express": "^4.17.1",
    "express-handlebars": "^3.1.0",
    "mongodb": "^3.2.6",
    "mysql": "^2.17.1"
  }
}

var express = require("express");
var bodyParser = require("body-parser");
var exphbs = require("express-handlebars");

var app = express();
var PORT = process.env.PORT || 3000;

app.use(express.static("public"));

app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(bodyParser.json());

app.engine("handlebars", exphbs({
    defaultLayout: "main"
}));
app.set("view engine", "handlebars");

var routes = require("./controllers/burgers_controller.js");
app.use(routes);

app.listen(port, "0.0.0.0", function () {
  console.log("Listening on Port 3000");
});

【问题讨论】:

    标签: javascript node.js heroku server web-deployment


    【解决方案1】:

    这对我有帮助。部署时默认的 buildpack 是 node.js 的。您需要使用 create-react-app buildpack(如下所示)。

    heroku create $APP_NAME --buildpack mars/create-react-app
    git push heroku master
    heroku open
    

    【讨论】:

      【解决方案2】:

      我可以看到您用大写字母声明了 PORT 变量。但是,在最后一行中,它以小写字母使用。尝试将其更改为:

      app.listen(PORT, "0.0.0.0", function () {
        console.log("Listening on Port 3000");
      });
      

      事实上,Express 会抛出一个 ReferenceError ,这会导致 Heroku 上的服务器崩溃。

      【讨论】:

      • 我尝试更改它,但我的应用程序仍然崩溃。我在这一点上迷路了。 :(
      【解决方案3】:

      检查这个答案

      React app runs locally, crashes when on Heroku error code=H10

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 2021-01-07
        • 1970-01-01
        • 2018-06-17
        • 2017-11-02
        • 2020-09-24
        • 1970-01-01
        • 1970-01-01
        • 2019-12-05
        • 2016-03-07
        相关资源
        最近更新 更多