将MEAN App部署到Heroku会产生H10错误& 503状态

时间:2015-08-14 20:08:41

标签: angularjs node.js heroku mean-stack

我正在学习MEAN堆栈并尝试了解Heroku如何同时工作。使用this教程,我将一个在我的机器上运行的工作应用程序放在一起。

当我尝试关注this教程和来自heroku的this教程时,一切正常,直到我尝试heroku open

在herokuapp.com上,页面显示为

Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

heroku logs --tail读取

2015-08-14T19:31:20.459454+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=shrouded-coast-5761.herokuapp.com request_id=e09a152f-9b52-4433-be2d-5c5a40150da7 fwd="166.170.43.70" dyno= connect= service= status=503 bytes=

找到回购here

当我heroku local web应用运行良好时。

1 个答案:

答案 0 :(得分:1)

看起来像是一些糟糕的配置。当我查看你的回购时,数据库配置引人注目。在 app.js 的最后一行,您有mongoose.connect('mongodb://localhost/news'); 以下是heroku mongoose documentation

中的一些代码
var http = require ('http');             // For serving a basic web page.
var mongoose = require ("mongoose"); // The reason for this demo.

// Here we find an appropriate database to connect to, defaulting to
// localhost if we don't find one.
var uristring =
    process.env.MONGOLAB_URI ||
    process.env.MONGOHQ_URL ||
    'mongodb://localhost/HelloMongoose';

// The http server will listen to an appropriate port, or default to
// port 5000.
var theport = process.env.PORT || 5000;

// Makes connection asynchronously.  Mongoose will queue up database
// operations and release them when the connection is complete.
mongoose.connect(uristring, function (err, res) {
if (err) {
   console.log ('ERROR connecting to: ' + uristring + '. ' + err);
} else {
  console.log ('Succeeded connected to: ' + uristring);
}
});

由于缺少数据库连接,您的应用看起来很糟糕。