我有 app.js
var express = require('express')
, routes = require('./routes')
, MemoryStore = new express.session.MemoryStore
, app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('restservice'));
app.use(express.session({store: MemoryStore, secret: '123456', key: 'sid', maxAge: 60000 }));
app.use(routes);
app.use(app.router);
});
路线/index.js
var express = require('express')
, tools = require('./../functions')
, app = module.exports = express();
app.get('/user/:id',tools.isAdmin,function(req,res){
console.log('isadmin');
});
和function.js
module.exports = {
isAdmin: function (res,req,next) {
if (req.session.level >= 16)
next();
else {
res.json({result:-1});
}
}
};
所以我的问题是当我访问http://myadmin.com/user/3时出现错误req.session undefined
我如何从 functions.js 的角度访问会话信息?