我一直在寻找解决方案,但是我尝试过的任何方法都给出了相同的结果。我认为它必须与本地主机有关,但我不知道出了什么问题。这些是我在运行 heroku 日志时遇到的错误。
2013-08-05T07:10:34.804131+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=node-beginners.herokuapp.com fwd="59.92.205.141" dyno= connect= service= status=503 bytes=
2013-08-05T07:10:35.424107+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=node-beginners.herokuapp.com fwd="59.92.205.141" dyno= connect= service= status=503 bytes=
2013-08-05T07:10:35.927263+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=node-beginners.herokuapp.com fwd="59.92.205.141" dyno= connect= service= status=503 bytes=
2013-08-05T07:20:26.552533+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
我的 server.js 文件看起来像这样。
//create an app server
var express = require('express')
, flash = require('connect-flash')
, helpers = require('view-helpers')
, mongoStore = require('connect-mongo')(express)
, fs = require('fs')
, mongoose = require('mongoose')
, passport=require('passport')
//create/connect to database
var dbname = 'test';
var uri = 'mongodb://localhost/' + dbname;
mongoose.connect(uri);
console.log('server.js : connecting to %s', uri);
//express settings
var app = express()
app.configure(function() {
app.use(express.static(__dirname + '/public'));
app.use(express.cookieParser('keyboard cat' ));
app.use(express.bodyParser());
app.use(express.methodOverride())
app.use(express.session({
secret: 'spoc',
store: new mongoStore({
url: 'mongodb://localhost/' + dbname,
collection : 'sessions'
})
}))
app.use(passport.initialize());
app.use(passport.session());
app.use(flash())
app.use(helpers('node-beginners'))
app.use(app.router);
});
//start app
var PORT = process.env.PORT || 3000
app.listen(PORT)
console.log('Express app started on port '+PORT)
//expose app
exports = module.exports = app
我已经尝试了几乎可以在其他帖子中找到的所有内容,但仍然出现此错误。请帮忙!