我有app.js與訪問會話信息的NodeJS
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
我該如何從函數.js視圖中獲取對會話信息的訪問權限?
你已經創建了兩個獨立的應用程序。我很驚訝什麼都記錄了。 – 2013-03-12 02:11:16