Heroku 不会 运行 mongolab 应用程序
Heroku won't run mongolab app
我正在按照 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 logs"
后的日志消息
2017-06-26T13:11:15.395121+00:00 heroku[router]: at=error code=H10
desc="App crashed" method=GET path="/"
host=herokudatabaseprovisioning.herokuapp.com
request_id=f2f3d85e-154c-4169-8c8c-9a1f4bdee05c fwd="137.132.242.118"
dyno= connect= service= status=503 bytes= protocol=https
2017-06-26T13:11:16.634793+00:00 heroku[router]: at=error code=H10
desc="App crashed" method=GET path="/favicon.ico"
host=herokudatabaseprovisioning.herokuapp.com
request_id=01d79a9d-0088-4dac-b582-79e08c8e0858 fwd="137.132.242.118
dyno= connect= service= status=503 bytes= protocol=https
此外,我已经仔细检查了一些解决 heroku 日志中这种错误类型的堆栈溢出答案,但所有这些都是由使用 node.js' 本机服务器 .listen()
方法引起的,none 的那些关于如何解决使用 mongodb 的 MongoClient.connect()
方法
的问题
如何解决这个问题?严重的是,我已经坚持了 2 周。
这是 github 中全部源代码的 the repo。
我刚看过你的package.json。您没有指定脚本参数。这是修改后的版本。还要确保将您的 procfile 重命名为 Procfile。
{
"name": "trial",
"version": "1.0.0",
"description": "Test for Hesington",
"scripts": {
"start": "node app.js"
},
"main": "app.js",
"dependencies": {
"mongodb": "^2.2.29"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"engines": {
"node": "6.10.3",
"npm": "5.0.2"
},
"license": "ISC",
"repository": {
"type": "git",
"url": "git+https://github.com/hesingon/FFCdbprovision.git"
},
"bugs": {
"url": "https://github.com/hesingon/FFCdbprovision/issues"
},
"homepage": "https://github.com/hesingon/FFCdbprovision#readme"
}
我正在按照 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 logs"
后的日志消息2017-06-26T13:11:15.395121+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=herokudatabaseprovisioning.herokuapp.com request_id=f2f3d85e-154c-4169-8c8c-9a1f4bdee05c fwd="137.132.242.118" dyno= connect= service= status=503 bytes= protocol=https
2017-06-26T13:11:16.634793+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=herokudatabaseprovisioning.herokuapp.com request_id=01d79a9d-0088-4dac-b582-79e08c8e0858 fwd="137.132.242.118 dyno= connect= service= status=503 bytes= protocol=https
此外,我已经仔细检查了一些解决 heroku 日志中这种错误类型的堆栈溢出答案,但所有这些都是由使用 node.js' 本机服务器 .listen()
方法引起的,none 的那些关于如何解决使用 mongodb 的 MongoClient.connect()
方法
如何解决这个问题?严重的是,我已经坚持了 2 周。 这是 github 中全部源代码的 the repo。
我刚看过你的package.json。您没有指定脚本参数。这是修改后的版本。还要确保将您的 procfile 重命名为 Procfile。
{
"name": "trial",
"version": "1.0.0",
"description": "Test for Hesington",
"scripts": {
"start": "node app.js"
},
"main": "app.js",
"dependencies": {
"mongodb": "^2.2.29"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"engines": {
"node": "6.10.3",
"npm": "5.0.2"
},
"license": "ISC",
"repository": {
"type": "git",
"url": "git+https://github.com/hesingon/FFCdbprovision.git"
},
"bugs": {
"url": "https://github.com/hesingon/FFCdbprovision/issues"
},
"homepage": "https://github.com/hesingon/FFCdbprovision#readme"
}