如何在Node.js中pipe理会话

我使用express.session和connect-mongo作为我的DataStore。

我所面对的是…在我的服务器中,我有20个不同的app.get()调用。 但并非所有人都需要检查会话。

但是,如果我在我的服务器的开始这样做:

express.createServer( express.session({ ... })); 

然后每一个呼叫都会触发express.session,从而设置一个会话给mongoDB。

如何限制我只想触发express.session?

 eg app.get('/getASession') will get a session app.get('/donotGetSession') will not even trigger express.session 

我找出解决办法。 express.session作为函数返回。 所以我可以这样做:

 global.mySession = express.session({ secret: session_secret, store:new MongoStore({ db: session_db_name, host: session_db_ip, port: session_db_port }) }); app.get('/checkSession', mySession, function (req, res) { res.send("<div>ok</div>"); }); 

所以,如果我不想使用session,那么我不会把mySession放在那里。 :)简单。 我爱结点。 :d