新的改动
npm install morgan
var logger = require('morgan')
app.use(logger(options))
将express与模块分开后不用express.logger()了,直接logger()
app.set('showStackError',true)
app.use(logger(':method :url :status'))
app.locals.pretty = true
mongoose.set('debug',true)
npm install morgan
var logger = require('morgan')
app.use(logger(options))
将express与模块分开后不用express.logger()了,直接logger()
app.set('showStackError',true)
app.use(logger(':method :url :status'))
app.locals.pretty = true
mongoose.set('debug',true)
2017-09-20
module.exports = function(app){}传出代码块,exports于module.exports初始指向空对象。但两者无关
require()传入代码块
require()传入代码块
2017-09-20
npm install connect-mongo --save 持久化会话中间件
把session定义在mongoose前面,否则出现Cannot read property 'Store' of undefined错误
把session定义在mongoose前面,否则出现Cannot read property 'Store' of undefined错误
2017-09-19
建立在connect.express上
var cookieParser = require('cookie-parser') //cookie解析的中间件sessionid
var session = require('express-session')//提供会话支持store对象
sid - sessionid
var cookieParser = require('cookie-parser') //cookie解析的中间件sessionid
var session = require('express-session')//提供会话支持store对象
sid - sessionid
2017-09-19
2. 如果#{item.from.name} , Cannot read property 'name' of undefined
解决方案:确定Schema, model , comment中的User都没错的情况下,删除数据库中已提交的评论,重新提交;
原因:之前ref "User"名字写错,或者是model 中 User名字写错,在写错的情况下提交了评论,在User改回来后,之前提交的Comment中from的User依旧是是错误的所以找不到User中的name;
解决方案:确定Schema, model , comment中的User都没错的情况下,删除数据库中已提交的评论,重新提交;
原因:之前ref "User"名字写错,或者是model 中 User名字写错,在写错的情况下提交了评论,在User改回来后,之前提交的Comment中from的User依旧是是错误的所以找不到User中的name;
2017-09-17
1. 如果渲染detail报user undefined 或 null 的异常
> routes.js
app.use(function(req, res, next) {
var _user = req.session.user;
if (_user) {
app.locals.user = _user;
}
else {
app.locals.user = new Object();
}
next();
})
> routes.js
app.use(function(req, res, next) {
var _user = req.session.user;
if (_user) {
app.locals.user = _user;
}
else {
app.locals.user = new Object();
}
next();
})
2017-09-17