redis session not working on server redis session not working on server express express

redis session not working on server


A few suggestions. Are you sure Redis uses the same port and password in production? If you're using SSL with a service like Heroku, you need to set proxy: true to have Express treat cookies that arrive after after earlier SSL termination.

   .use(express.session({        store: new RedisStore({            port: config.redisPort,            host: config.redisHost,            db: config.redisDatabase,            pass: config.redisPassword}),        secret: 'sauce',        proxy: true,        cookie: { secure: true }    }))

I require the following config.js file to pass on Redis config values:

var url = require('url')var config = {};var redisUrl;if (typeof(process.env.REDISTOGO_URL) != 'undefined') {    redisUrl = url.parse(process.env.REDISTOGO_URL);}else redisUrl = url.parse('redis://:@127.0.0.1:6379/0');config.redisProtocol = redisUrl.protocol.substr(0, redisUrl.protocol.length - 1); // Remove trailing ':'config.redisUsername = redisUrl.auth.split(':')[0];config.redisPassword = redisUrl.auth.split(':')[1];config.redisHost = redisUrl.hostname;config.redisPort = redisUrl.port;config.redisDatabase = redisUrl.path.substring(1);console.log('Using Redis store ' + config.redisDatabase)module.exports = config;