var connect = require(‘connect’); var app = connect(); app.use(connect.logger(‘dev’)); app.use(connect.cookieParser(‘dd’)); app.use(connect.session({secret:’123’})); app.use(function(req,res,next){ if(req.session.pv){ res.writeHeader('200’,{’Content-type’:’text/html’}); res.write('views: ' + req.session.pv); res.end(); req.session.pv ++; }else{ req.session.pv = 1; res.end(‘Refresh’); }
}) app.listen(3000);
这是一个很坑爹的问题,req.session.pv每一次都是双数,如:2,4,6,8但是req.session.pv只是每次自加1而已