sessions.js 712 Bytes

// # boot - sessions

var session = require('express-session');
var RedisStore = require('connect-redis').default;
var createClient = require('redis');

exports = module.exports = function(logger, settings) {

  // Initialize client.
  let redisClient = createClient()
  redisClient.connect().catch(console.error)

  var connection = new RedisStore({
    client: redisClient,
    ...settings.redis
  })

  connection.on('error', function(err) {
    logger.error('redis connection error: %s', err.message || err)
  })

  connection.on('connect', function() {
    logger.info('redis connected')
  })

  return connection

}

exports['@singleton'] = true
exports['@require'] = [ 'igloo/logger', 'igloo/settings' ]