似乎是在将几个误区github指南(或者它为老版本的keystone写的)。也就是说,以下两行会带来麻烦:
keystone.static(app);
keystone.mongoose.connect.on('error', handleDbErrorsFunc);
我评论者淘汰,并指出该数据库,以我的本地的MongoDB。我还处理了从产生的keystone项目中的models/User.js
。就这样,我有工作(虽然没有任何CSS)的管理员控制
如果你想切磋,这是我的编辑您的指南的版本:
var express = require('express'),
app = express(),
keystone = require('keystone'),
session = require('express-session'),
flash = require('connect-flash'),
serve = require('serve-static'),
favicon = require('serve-favicon'),
body = require('body-parser'),
mongoose = require('mongoose'),
cookieParse = require('cookie-parser'),
multer = require('multer');
app.set('port', process.env.PORT || 9000);
app.set('view engine', 'jade');
// app.use(favicon(__dirname + '/public/images/favicon.ico'));
app.use(cookieParse());
app.use(body.urlencoded({
extended: true
}));
app.use(body.json());
app.use(multer());
//Session and flash are required by keystone
app.use(flash());
app.use(session({
secret: 'Keystone is the best!',
resave: false,
saveUninitialized: true
}));
keystone.app = app;
keystone.mongoose = mongoose;
keystone.init({
'user model': 'User',
'mongo': 'mongodb://localhost/keystone',
'session': true,
'static': 'public'
});
// Let keystone know where your models are defined. Here we have it at the `/models`
keystone.import('models');
// Set keystone's to serve it's own public files. for instance, its logo's and stylesheets
// keystone.static(app);
// Set keystone routes for the admin panel, located at '/keystone'
keystone.routes(app);
// Initialize keystone's connection the database
keystone.mongoose.connect(keystone.get('mongo'));
// Create a handler for DB connection errors
// keystone.mongoose.connect.on('error', handleDbErrorsFunc);
// Serve your static assets
app.use(serve('./public'));
// This is where your normal routes and files are handled
app.get('/', function(req, res, next) {
res.send('hello world');
});
// Start your express server
app.listen(app.get('port'));