带有Passport崩溃的Node.JS应用程序

时间:2013-12-27 09:37:36

标签: node.js heroku express passport.js passport-facebook

我的应用在本地工作。我添加了我认为Heroku必要的所有内容

Procfile

web: node app.js

的package.json

{
  "name": "HipsterMatch",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "nodemon app.js"
  },
  "dependencies": {
    "express": "3.1.0",
    "jade": "*",
    "mongodb": "*",
    "nodemon": "0.7.10",
    "passport": "*",
    "passport-local": "*",
    "passport-facebook": "*",
    "mongoose": "~3.6.4",
    "connect-flash": "*"
  },
  "engines": {
    "node": "0.10.1",
    "npm": "1.3.14"
  }
}

这是我的日志

2013-12-27T08:40:29.457548+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=hipsterlove.herokuapp.com fwd="162.205.69.18" dyno= connect= service= status=503 bytes=
2013-12-27T08:44:38.166741+00:00 heroku[api]: Add mongohq:sandbox add-on by     jgallardo720@gmail.com
2013-12-27T08:44:38.186021+00:00 heroku[api]: Release v5 created by jgallardo720@gmail.com
2013-12-27T08:44:38.327041+00:00 heroku[web.1]: State changed from crashed to starting
2013-12-27T08:44:40.396197+00:00 heroku[web.1]: Starting process with command `node app.js`
2013-12-27T08:44:42.090303+00:00 app[web.1]: Express server listening on port 37441
2013-12-27T08:44:42.092470+00:00 app[web.1]:
2013-12-27T08:44:42.092672+00:00 app[web.1]: events.js:72
2013-12-27T08:44:42.092911+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-12-27T08:44:42.092911+00:00 app[web.1]: ^
2013-12-27T08:44:42.095509+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-12-27T08:44:42.095509+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-12-27T08:44:42.095509+00:00 app[web.1]: at EventEmitter.emit (events.js:106:17)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at EventEmitter.emit (events.js:98:17)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at net.js:426:14
2013-12-27T08:44:43.403162+00:00 heroku[web.1]: Process exited with status 8
2013-12-27T08:44:43.421294+00:00 heroku[web.1]: State changed from starting to crashed
2013-12-27T08:45:03.209570+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=hipsterlove.herokuapp.com fwd="162.205.69.18" dyno= connect= service= status=503 bytes=
2013-12-27T08:47:32.961418+00:00 heroku[api]: Add papertrail:choklad add-on by jgallardo720@gmail.com
2013-12-27T08:47:33.079955+00:00 heroku[api]: Release v6 created by jgallardo720@gmail.com
2013-12-27T08:47:33.710788+00:00 heroku[web.1]: State changed from crashed to starting
2013-12-27T08:47:36.186033+00:00 heroku[web.1]: Starting process with command `node app.js`
2013-12-27T08:47:37.958627+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-12-27T08:47:37.958627+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-12-27T08:47:37.958627+00:00 app[web.1]: at EventEmitter.emit (events.js:106:17)
2013-12-27T08:47:37.954398+00:00 app[web.1]: ^
2013-12-27T08:47:37.949510+00:00 app[web.1]: Express server listening on port 32125
2013-12-27T08:47:37.952974+00:00 app[web.1]:
2013-12-27T08:47:37.953554+00:00 app[web.1]: events.js:72
2013-12-27T08:47:37.954045+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-12-27T08:47:37.958627+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-12-27T08:47:37.958627+00:00 app[web.1]: at EventEmitter.emit (events.js:98:17)
2013-12-27T08:47:37.958627+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-12-27T08:47:37.958627+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-12-27T08:47:37.958627+00:00 app[web.1]: at net.js:426:14
2013-12-27T08:47:37.958627+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
2013-12-27T08:47:39.133359+00:00 heroku[web.1]: State changed from starting to crashed
2013-12-27T08:47:39.134204+00:00 heroku[web.1]: State changed from crashed to starting
2013-12-27T08:47:39.120176+00:00 heroku[web.1]: Process exited with status 8
2013-12-27T08:47:41.463835+00:00 heroku[web.1]: Starting process with command `node app.js`
2013-12-27T08:47:42.782433+00:00 app[web.1]: Express server listening on port 7709
2013-12-27T08:47:42.784187+00:00 app[web.1]:
2013-12-27T08:47:42.784508+00:00 app[web.1]: events.js:72
2013-12-27T08:47:42.784983+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-12-27T08:47:42.784983+00:00 app[web.1]: ^
2013
-12-27T08:47:42.787164+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-12-27T08:47:42.787164+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at EventEmitter.emit (events.js:106:17)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at EventEmitter.emit (events.js:98:17)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at net.js:426:14
2013-12-27T08:47:42.787164+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
2013-12-27T08:47:44.091837+00:00 heroku[web.1]: Process exited with status 8
2013-12-27T08:47:44.093316+00:00 heroku[web.1]: State changed from starting to crashed
2013-12-27T08:50:30+00:00 heroku[slug-compiler]: Slug compilation started
2013-12-27T08:50:55.506146+00:00 heroku[api]: Deploy 36c405b by jgallardo720@gmail.com
2013-12-27T08:50:55.532599+00:00 heroku[api]: Release v7 created by jgallardo720@gmail.com
2013-12-27T08:50:55+00:00 heroku[slug-compiler]: Slug compilation finished
2013-12-27T08:50:55.924898+00:00 heroku[web.1]: State changed from crashed to starting
2013-12-27T08:50:57.601471+00:00 heroku[web.1]: Starting process with command `node app.js`
2013-12-27T08:50:58.821299+00:00 app[web.1]: Express server listening on port 44602
2013-12-27T08:50:58.823409+00:00 app[web.1]: events.js:72
2013-12-27T08:50:58.823687+00:00 app[web.1]: ^
2013-12-27T08:50:58.823080+00:00 app[web.1]:
2013-12-27T08:50:58.823687+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-12-27T08:50:58.826090+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-12-27T08:50:58.826090+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-12-27T08:50:58.826090+00:00 app[web.1]: at EventEmitter.emit (events.js:98:17)
2013-12-27T08:50:58.826090+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-12-27T08:50:58.826090+00:00 app[web.1]: at EventEmitter.emit (events.js:106:17)
2013-12-27T08:50:58.826090+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-12-27T08:50:58.826090+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-12-27T08:50:58.826090+00:00 app[web.1]: at net.js:426:14
2013-12-27T08:50:58.826090+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
2013-12-27T08:50:59.977120+00:00 heroku[web.1]: Process exited with status 8
2013-12-27T08:50:59.998919+00:00 heroku[web.1]: State changed from starting to crashed
2013-12-27T08:57:32.833792+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=hipsterlove.herokuapp.com fwd="174.251.209.112" dyno= connect= service= status=503 bytes=
2013-12-27T09:01:35.385263+00:00 heroku[web.1]: Starting process with command `node app.js`
2013-12-27T09:01:36.760608+00:00 app[web.1]: events.js:72
2013-12-27T09:01:36.758539+00:00 app[web.1]: Express server listening on port 4749
2013-12-27T09:01:36.760891+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-12-27T09:01:36.760257+00:00 app[web.1]:
2013-12-27T09:01:36.761120+00:00 app[web.1]: ^
2013-12-27T09:01:36.763625+00:00 app[web.1]: at EventEmitter.emit (events.js:98:17)
2013-12-27T09:01:36.763625+00:00 app[web.1]: at EventEmitter.emit (events.js:106:17)
2013-12-27T09:01:36.763625+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-12-27T09:01:36.763625+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-12-27T09:01:36.763625+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-12-27T09:01:36.763625+00:00 app[web.1]: at net.js:426:14
2013-12-27T09:01:36.763625+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
2013-12-27T09:01:36.763625+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-12-27T09:01:36.763625+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-12-27T09:01:37.955733+00:00 heroku[web.1]: Process exited with status 8
2013-12-27T09:01:37.987115+00:00 heroku[web.1]: State changed from starting to crashed
2013-12-27T09:01:33.253022+00:00 heroku[web.1]: State changed from crashed to starting

1 个答案:

答案 0 :(得分:0)

看起来你正在引用你的本地mongoDB实例:

Error: failed to connect to [localhost:27017]

我想你已经对这些价值进行了硬编码......

处理从环境变为环境的连接字符串的推荐方法是使用环境变量(http://12factor.net/config)。

所以你需要做以下事情(如果你还没有)。

1)在云中设置一个mongo实例(MongoHQ,mongoLab等)(heroku使这相当容易)。

2)如果heroku没有为连接字符串设置env变量,那么你需要这样做。

列出你的环境(在命令行中输入):

heroku config -a name_of_your_heroku_app

设置您的环境

heroku config:set MONGO_URL=somethingGoesHere -a name_of_your_heroku_app

然后在您的节点代码中,您可以像这样引用该值:

var url = process.env.MONGO_URL;

要在本地设置env变量,请在应用的根目录中创建.env文件。运行foreman start将运行您的procfile以及将.env变量加载到内存中。