express - 什么可能导致此heroku崩溃?错误代码=H10

标签 express heroku sequelize.js auth0

我查看了过去关于这个问题的帖子,许多人建议重新启动 heroku,或重新启动 dynos,或确保使用 var PORT = process.env.PORT || 3000. 我已经做了所有这些,但我的应用程序仍然崩溃。该应用程序使用 node/express sequelize/auth0 运行。

有没有人有什么建议?谢谢!

以下是日志:

 2017-09-08T02:11:37.293051+00:00 app[web.1]:     at emitOne 
(events.js:96:13)
2017-09-08T02:11:37.293052+00:00 app[web.1]:     at Socket.emit 
(events.js:188:7)
2017-09-08T02:11:37.293053+00:00 app[web.1]:     at emitErrorNT 
(net.js:1277:8)
2017-09-08T02:11:37.293054+00:00 app[web.1]:     at 
_combinedTickCallback (internal/process/next_tick.js:80:11)
2017-09-08T02:11:37.293055+00:00 app[web.1]:     at 
process._tickCallback (internal/process/next_tick.js:104:9)
2017-09-08T02:11:37.364314+00:00 heroku[web.1]: State changed from 
starting to crashed
2017-09-08T02:11:37.353673+00:00 heroku[web.1]: Process exited with 
status 0
2017-09-08T02:11:49.712881+00:00 heroku[router]: at=error code=H10 
desc="App crashed" method=GET path="/" host=roadie2.herokuapp.com 
request_id=79e0bc3a-aa28-44bb-ab80-cfcf4f6cd97d fwd="99.92.51.34" 
dyno= connect= service= status=503 bytes= protocol=https
2017-09-08T02:11:50.564503+00:00 heroku[router]: at=error code=H10 
desc="App crashed" method=GET path="/favicon.ico" 
host=roadie2.herokuapp.com request_id=c72e5077-494c-41f5-8be1-
f0c2c329d080 fwd="99.92.51.34" dyno= connect= service= status=503 
bytes= protocol=https
2017-09-08T02:12:24.838901+00:00 heroku[router]: at=error code=H10 
desc="App crashed" method=GET path="/" host=roadie2.herokuapp.com 
request_id=ca551858-5372-40c9-abf1-670176b159dc fwd="99.92.51.34" 
dyno= connect= service= status=503 bytes= protocol=https
2017-09-08T02:12:25.340624+00:00 heroku[router]: at=error code=H10 
desc="App crashed" method=GET path="/favicon.ico" 
host=roadie2.herokuapp.com request_id=c37b876d-5a59-40d0-9d59-
9be013c58d94 fwd="99.92.51.34" dyno= connect= service= status=503 
bytes= protocol=https

这是输入heroku logs --tail 后结果的最后一部分
2017-09-08T02:11:27.589912+00:00 heroku[web.1]: State changed from 
crashed to starting
2017-09-08T02:11:29.599921+00:00 heroku[web.1]: Starting process with 
command `npm start`
2017-09-08T02:11:32.504222+00:00 app[web.1]:
2017-09-08T02:11:32.504242+00:00 app[web.1]: > 15.2@1.0.0 start /app
2017-09-08T02:11:32.504243+00:00 app[web.1]: > node server.js
2017-09-08T02:11:32.504243+00:00 app[web.1]:
2017-09-08T02:11:33.199936+00:00 app[web.1]: Unhandled rejection 
SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
2017-09-08T02:11:33.199952+00:00 app[web.1]:     at 
Handshake._callback 
(/app/node_modules/sequelize/lib/dialects/mysql/connection-
manager.js:80:20)
2017-09-08T02:11:33.199953+00:00 app[web.1]:     at 
Protocol.handleNetworkError 
(/app/node_modules/mysql/lib/protocol/Protocol.js:364:14)
2017-09-08T02:11:33.199953+00:00 app[web.1]:     at 
Connection._handleNetworkError 
(/app/node_modules/mysql/lib/Connection.js:428:18)
2017-09-08T02:11:33.199954+00:00 app[web.1]:     at emitOne 
(events.js:96:13)
2017-09-08T02:11:33.199952+00:00 app[web.1]:     at 
Handshake.Sequence.end 
(/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:86:24)
2017-09-08T02:11:33.199954+00:00 app[web.1]:     at Socket.emit 
(events.js:188:7)
2017-09-08T02:11:33.199955+00:00 app[web.1]:     at emitErrorNT 
(net.js:1277:8)
2017-09-08T02:11:33.199956+00:00 app[web.1]:     at 
_combinedTickCallback (internal/process/next_tick.js:80:11)
2017-09-08T02:11:33.199956+00:00 app[web.1]:     at 
process._tickCallback (internal/process/next_tick.js:104:9)
2017-09-08T02:11:33.302346+00:00 heroku[web.1]: State changed from 
starting to crashed
2017-09-08T02:11:33.305267+00:00 heroku[web.1]: State changed from . 
crashed to starting
2017-09-08T02:11:33.286200+00:00 heroku[web.1]: Process exited with . 
status 0
2017-09-08T02:11:34.845606+00:00 heroku[web.1]: Starting process with 
command `npm start`
2017-09-08T02:11:36.543285+00:00 app[web.1]:
2017-09-08T02:11:36.543298+00:00 app[web.1]: > 15.2@1.0.0 start /app
2017-09-08T02:11:36.543299+00:00 app[web.1]: > node server.js
2017-09-08T02:11:36.543299+00:00 app[web.1]:
2017-09-08T02:11:37.293030+00:00 app[web.1]: Unhandled rejection . 
SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
2017-09-08T02:11:37.293048+00:00 app[web.1]:     at 
Handshake._callback . 
(/app/node_modules/sequelize/lib/dialects/mysql/connection-
manager.js:80:20)
2017-09-08T02:11:37.293049+00:00 app[web.1]:     at 
Handshake.Sequence.end 
(/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:86:24)
2017-09-08T02:11:37.293049+00:00 app[web.1]:     at . 
Protocol.handleNetworkError 
(/app/node_modules/mysql/lib/protocol/Protocol.js:364:14)
2017-09-08T02:11:37.293050+00:00 app[web.1]:     at 
Connection._handleNetworkError 
(/app/node_modules/mysql/lib/Connection.js:428:18)
2017-09-08T02:11:37.293051+00:00 app[web.1]:     at emitOne 
(events.js:96:13)
2017-09-08T02:11:37.293052+00:00 app[web.1]:     at Socket.emit 
(events.js:188:7)
2017-09-08T02:11:37.293053+00:00 app[web.1]:     at emitErrorNT 
(net.js:1277:8)
2017-09-08T02:11:37.293054+00:00 app[web.1]:     at 
_combinedTickCallback (internal/process/next_tick.js:80:11)
2017-09-08T02:11:37.293055+00:00 app[web.1]:     at 
process._tickCallback (internal/process/next_tick.js:104:9)
2017-09-08T02:11:37.364314+00:00 heroku[web.1]: State changed from 
starting to crashed
2017-09-08T02:11:37.353673+00:00 heroku[web.1]: Process exited with . 
status 0
2017-09-08T02:11:49.712881+00:00 heroku[router]: at=error code=H10 . 
desc="Appcrashed" method=GET path="/" host=roadie2.herokuapp.com 
request_id=79e0bc3a-aa28-44bb-ab80-cfcf4f6cd97d fwd="99.92.51.34" 
dyno= connect= service= status=503 bytes= protocol=https
2017-09-08T02:11:50.564503+00:00 heroku[router]: at=error code=H10 
desc="Appcrashed" method=GET path="/favicon.ico" 
host=roadie2.herokuapp.com request_id=c72e5077-494c-41f5-8be1-
f0c2c329d080 fwd="99.92.51.34" dyno= connect= service= status=503 
bytes= protocol=https
2017-09-08T02:12:24.838901+00:00 heroku[router]: at=error code=H10 . 
desc="Appcrashed" method=GET path="/" host=roadie2.herokuapp.com 
request_id=ca551858-5372-40c9-abf1-670176b159dc fwd="99.92.51.34" 
dyno= connect= service= status=503 bytes= protocol=https
2017-09-08T02:12:25.340624+00:00 heroku[router]: at=error code=H10 
desc="Appcrashed" method=GET path="/favicon.ico" 
host=roadie2.herokuapp.com request_id=c37b876d-5a59-40d0-9d59-
9be013c58d94 fwd="99.92.51.34" dyno= connect= service= status=503 
 bytes= protocol=https

配置文件
 {
 "development": {
"username": "root",
"password":"",
"database": "roadie2",
"host": "127.0.0.1",
"dialect": "mysql"
 },
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
 },
 "production": {
"use_env_variable": "JAWSDB_URL",
"dialect": "mysql"
}
}

服务器.js
var express = require("express");
var bodyParser = require("body-parser");

// Sets up the Express App
// =============================================================
var app = express();
// var PORT = process.env.PORT || 3000;
var port = process.env.PORT 

// Requiring our models for syncing
var db = require("./models");

// Sets up the Express app to handle data parsing
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text());
app.use(bodyParser.json({ type: "application/vnd.api+json" }));



// Static directory
app.use(express.static("./public"));

// Routes =============================================================

require("./routes/html-routes.js")(app);
require("./routes/api-routes.js")(app);

// Syncing our sequelize models and then starting our express app
db.sequelize.sync().then(function() {
  app.listen(port, function() {
    console.log("App listening on PORT " + port);
  });

});

模型/index.js
'use strict';

var fs        = require('fs');
var path      = require('path');
var Sequelize = require('sequelize');
var basename  = path.basename(module.filename);
var env       = process.env.NODE_ENV || 'development';
var config    = require(__dirname + '/../config/config.json')[env];
var db        = {};

if (config.use_env_variable) {
  var sequelize = new 
Sequelize(process.env[config.use_env_variable]);
} else {
  var sequelize = new Sequelize(config.database, config.username, 
config.password, config);
}

fs
  .readdirSync(__dirname)
  .filter(function(file) {
    return (file.indexOf('.') !== 0) && (file !== basename) && 
(file.slice(-3) === '.js');
  })
  .forEach(function(file) {
    var model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
 });

Object.keys(db).forEach(function(modelName) {
  if (db[modelName].associate) {
  db[modelName].associate(db);
 }
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;

最佳答案

https://devcenter.heroku.com/articles/error-codes#h10-app-crashed

您的日志清楚地告诉您崩溃的原因:

2017-09-08T02:11:37.293030+00:00 app[web.1]: Unhandled rejection . 
SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306

您无法连接到您的 SQL 服务器。

从它的外观来看,您似乎正在尝试连接到 127.0.0.1:3306 ,但它不起作用。 127.0.0.1localhost 是您的本地 IP。

您需要设置/连接到 Heroku's Postgres 插件或使用外部 SQL 服务,例如 Amazon RDS

关于express - 什么可能导致此heroku崩溃?错误代码=H10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46107749/

相关文章:

javascript - 将 MongoDB 数据传递给 ExpressJS 中的 Jade View

javascript - 从 nodejs 以 html 格式共享文件

javascript - Heroku 创建命令产生 "ENOENT"错误

node.js - 使用 Sequelize 进行不同计数

node.js - 如何使用 mongoose 的 findOneAndUpdate 方法更新嵌入对象的某些字段而不丢失其他字段?

javascript - 在Node JS数据库类上插入之前检查记录是否存在

python - 将纯 python 部署到 heroku

database - 如何将 .sql 文件导入我的 Heroku postgres 数据库?

mysql - Node.js脚本过早退出

javascript - Sequelize : How associate two fields from a table another table