Node.JS Passport 崩溃的应用程序



我的应用程序在本地运行。我添加了我认为对 Heroku 必要的所有内容

Procfile

web: node app.js

包.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

看起来在 prod 中您正在引用您的本地 mongoDB 实例:

Error: failed to connect to [localhost:27017]

我想你已经硬编码了这些值...

处理此类因环境而异的连接字符串的建议方法是使用环境变量 (http://12factor.net/config)。

因此,您需要执行以下操作(如果尚未执行以下操作)。

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

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

要列出您的 env var(在命令行中输入):

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 变量加载到内存中。

最新更新