部署Heroku(代码h10)时,应用程序崩溃

时间:2019-06-19 12:43:48

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

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

这是我得到的错误:

  

2019-06-19T12:32:14.679424 + 00:00 heroku [router]:at =错误代码= H10   desc =“应用程序崩溃”方法=获取路径=“ /”   host = guarded-island-18465.herokuapp.com   request_id = 66a60c63-3bad-47ad-8255-85f56798df95fwd =“ 97.99.40.66” dyno =   connect =服务=状态= 503字节=   protocol = https2019-06-19T12:32:15.283697 + 00:00 heroku [router]:   at =错误代码= H10 desc =“应用程序崩溃”,方法= GET path =“ / favicon.ico”   host = guarded-island-18465.herokuapp.com   request_id = 888cb97b-7aaf-4e0b-97c5-d01432d188a6 fwd =“ 97.99.40.66”   dyno = connect = service = status = 503字节= protocol = 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");
});

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

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

就这样,Express会抛出ReferenceError,这将使Heroku上的服务器崩溃。

答案 2 :(得分:0)