【发布时间】:2018-09-14 16:37:15
【问题描述】:
我正在遵循来自 this freecodecamp post 的确切说明(除了我没有存储和使用连接 URI .env 变量),但应用程序的网页显示“应用程序中发生错误,您的页面可能不送达。如果您是应用程序所有者,请查看您的日志以了解详细信息。'
以下是我的 app.js 中的内容,我非常肯定用户名和密码正确且格式正确。
//lets require/import the mongodb native drivers.
var mongodb = require('mongodb');
//We need to work with "MongoClient" interface in order to connect to a mongodb server.
var MongoClient = mongodb.MongoClient;
// Connection URL. This is where your mongodb server is running.
//(Focus on This Variable)
var url = 'mongodb://user1:123456@ds139959.mlab.com:39959/url-shortener';
//'mongodb://user1:123456@ds139959.mlab.com:39959/url-shortener';
//(Focus on This Variable)
// Use connect method to connect to the Server
MongoClient.connect(url, function (err, db) {
if (err) {
console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
console.log('Connection established to', url);
// do some work here with the database.
//Close connection
db.close();
}
});
这是我输入“heroku 日志”后的日志消息
2017-06-26T13:11:15.395121+00:00 heroku[路由器]: at=error code=H10 desc="应用程序崩溃" 方法=GET 路径="/" 主机=herokudatabaseprovisioning.herokuapp.com request_id=f2f3d85e-154c-4169-8c8c-9a1f4bdee05c fwd="137.132.242.118" dyno=连接=服务=状态=503字节=协议=https
2017-06-26T13:11:16.634793+00:00 heroku[路由器]: at=error code=H10 desc="应用程序崩溃" 方法=GET path="/favicon.ico" 主机=herokudatabaseprovisioning.herokuapp.com request_id=01d79a9d-0088-4dac-b582-79e08c8e0858 fwd="137.132.242.118 dyno=连接=服务=状态=503字节=协议=https
此外,我从 heroku 日志中仔细检查了一些解决此错误类型的堆栈溢出答案,但所有这些都是由使用 node.js 的本机服务器 .listen() 方法引起的,没有一个解决问题的方法使用mongodb的MongoClient.connect()method
如何解决这个问题?严重的是,我已经被困在这两个星期了。 这是github中全部源代码的the repo。
【问题讨论】: