heroku错误代码= H10获取路径/

时间:2018-07-03 14:22:57

标签: node.js heroku deployment

在尝试将简单的node.js应用程序部署到heroku时遇到以下错误,不确定发生了什么。一直在拉扯我的头发,试图解决这个问题,但是没有道理。

at=error code=H10 desc="App crashed" method=GET path="/" host=burger84.herokuapp.com request_id=c14ac113-b601-4803-80b3-6e50eecd3e88 fwd="129.171.249.144" dyno= connect= service= status=503 bytes= protocol=https
2018-07-03T13:54:08.326927+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=84.herokuapp.com request_id=3fb5a672-42d5-459a-8d84-bedd2e24eeaf fwd="129.171.249.144" dyno= connect= service= status=503 bytes= protocol=https
2018-07-03T14:01:25.312809+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=84.herokuapp.com request_id=a8f0519f-c03a-4d17-abf0-9158742ff211 fwd="129.171.249.144" dyno= connect= service= status=503 bytes= protocol=https
2018-07-03T14:01:25.626536+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=84.herokuapp.com request_id=938dbfed-b8d4-470c-937e-3bcedc50ee32 fwd="129.171.249.144" dyno= connect= service= status=503 bytes= protocol=https

我看到在线人们正在谈论process.env.PORT来解决此问题,但是我在server.js文件中使用了它:

    //server.js
    var express = require('express');
    var bodyParser = require('body-parser');
    var methodOverride = require('method-override');
    var exphbs = require('express-handlebars');
    var routes = require('./controllers/routes.js');


    var app = express();
    app.use(express.static(__dirname + '/public'));

    app.use(bodyParser.urlencoded({
        extended: false
    }))

    app.use(methodOverride('_method'));

    app.engine('handlebars', exphbs({
        defaultLayout: 'main'
    }))

    app.set('view engine', 'handlebars');
    app.use('/', routes);


    var PORT = process.env.PORT || 8080;
    app.listen(PORT, function(){
        console.log("Server listening on: http://localhost:" + PORT);
    }); 

    //package.json
   {
  "name": "burger",
  "version": "1.0.0",
  "description": "Making a yummy burger using node.js, mysql and a custom ORM",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.18.3",
    "express": "^4.16.3",
    "express-handlebars": "^3.0.0",
    "method-override": "^2.3.10",
    "mysql": "^2.15.0"
  },
  "devDependencies": {},
  "repository": {
    "type": "git",
    "url": "git+https://github.com/eliot84/burger.git"
  },
  "bugs": {
    "url": "https://github.com/eliot84/burger/issues"
  },
  "homepage": "https://github.com/eliot84/burger#readme"
}

1 个答案:

答案 0 :(得分:0)

好吧,进一步查看日志,我看到了:

    Error: connect ECONNREFUSED 127.0.0.1:3306
   2018-07-03T14:34:56.086385+00:00 app[web.1]:     at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:145:48)
2018-07-03T14:34:56.086387+00:00 app[web.1]:     at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:52:23)
2018-07-03T14:34:56.086388+00:00 app[web.1]:     at Connection.connect (/app/node_modules/mysql/lib/Connection.js:130:18)

问题出在我的应用程序中,因为mysql的配置文件仍指向我已设置的本地主机端口,需要更新为Web主机用户密码