我尝试使用Mongo-Express来查找我的mongoDB,我是新手,在我使用了用户并通过后我得到了错误 - >不能GET /
var express = require('express')
, routes = require('./routes')
, http = require('http');
var _ = require('underscore');
var async = require('async');
var utils = require('./utils');
var mongodb = require('mongodb');
var cons = require('consolidate');
var swig = require('swig');
var swigFilters = require('./filters');
var app = express();
var config = require('./config');
//Set up swig
app.engine('html', cons.swig);
Object.keys(swigFilters).forEach(function (name) {
swig.setFilter(name, swigFilters[name]);
});
//App configuration
app.configure(function(){
if(config.useBasicAuth){
app.use(express.basicAuth(config.basicAuth.username, config.basicAuth.password));
}
app.set('views', __dirname + '/views');
app.set('view engine', 'html');
app.set('view options', {layout: false});
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(config.site.baseUrl,express.static(__dirname + '/public'));
app.use(express.bodyParser());
app.use(express.cookieParser(config.site.cookieSecret));
app.use(express.session({
secret: config.site.sessionSecret,
key: config.site.cookieKeyName
}));
app.use(express.methodOverride());
app.use(app.router);
});
答案 0 :(得分:1)
首先,尝试从实际/更新的教程中学习。实际快递版本为4,它将删除:
app.use(app.router);
(因此我扣除了过时的教程) 第二件事,我没有在你的代码中看到任何路线。如果要从服务器获取响应,则需要编写路由。例如:
app.get('/test', function(req, res) {
res.send('Hello from route');
});