这个简单的例子不起作用。在每个请求中都会再次创建会话,我不知道如何解决它。
var express = require('express'),
expressSession = require('express-session'),
app = express();
app.use(expressSession({
secret:'secret',
resave:true,
saveUninitialized:true,
cookie:{
httpOnly:false,
expires:false
}
}));
app.all('/',function(req,res,next){
var session = req.session;
if(session.count){
session.count++;
}
else{
session.count = 1;
}
console.log('id:',req.sessionID);
console.log('count:',session.count);
res.end();
});
app.listen(9090);
console.log('server is running at http://localhost:9090');
我试图保存请求的计数,但每次我发出请求时都会创建会话。
//request
>GET http://localhost:9090
//response
id: gOqbVisxaW34qafRdb7-6shqYV0UurRg
count: 1
//request again
>GET http://localhost:9090
//response
id: P2iyXKHElJF8u86tHu7mIl7Encteebju
count: 1