Node.js server restart drops the sessions

后端 未结 5 1762
Happy的楠姐
Happy的楠姐 2020-12-24 03:40

I\'m having fully functional user signup/authentication system using express and connect middleware.

app.use(express.session({store: require(\'connect\').ses         


        
5条回答
  •  不知归路
    2020-12-24 04:05

    I was trying to get Redis on track using express.js, Google sent me here. The express implementation changed:

    var express = require('express'),
    RedisStore = require('connect-redis')(express);
    

    Another important thing is the order of express configurations.

    app.configure(function(){
    
        app.enable('strict routing'); // removes trailing slash
        app.set('views', __dirname + '/views');
        app.set('view engine', 'jqtpl');
        app.register('.html', require('jqtpl').express);
        app.use(express.favicon());
        app.use(express.methodOverride());
        app.use(express.compiler({src: __dirname + '/public', enable: ['sass']}));
        app.use(express.static(__dirname + '/public'));
        app.use(app.router);
        app.use(express.bodyParser());
        app.use(express.cookieParser());
        app.use(express.session({secret: _.config.secret, store: new RedisStore}));
    
    });
    

    cookieParser & session configurations need to be at the end of the configurations, and cookieParser must be placed right before express.session.

    Hope that helps, I ran in both of these problems.

提交回复
热议问题