# All files / server-old/plugins/session index.js

83.33% Statements 10/12
50% Branches 3/6
75% Functions 3/4
83.33% Lines 10/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    5026x
    26x
    26x
    26x
    26x

    26x

    106x

    106x

    107x

    106x

     const modern = require('../../src/modern');
    const server = require('../../server');
    const session = require('express-session');
    server.session = session;
    const RedisStore = require('connect-redis')(server.session);
    let sessionMiddleware;

    module.exports = {
      name: 'session',
      options: {
        __root: 'secret',
        resave: {
          default: false
        },
        saveUninitialized: {
          default: true
        },
        cookie: {
          default: {}
        },
        secret: {
          type: String,
          inherit: 'secret',
          env: 'SESSION_SECRET'
        },
        store: {
          env: false
        },
        redis: {
          type: String,
          inherit: true,
          env: 'REDIS_URL'
        }
      },
      init: ctx => {
        Iif (!ctx.options.session.store && ctx.options.session.redis) {
          ctx.options.session.store = new RedisStore({
            url: ctx.options.session.redis
          });
        }
        sessionMiddleware = session(ctx.options.session);
      },
      before: ctx => modern(sessionMiddleware)(ctx),
      launch: ctx => {
        ctx.io.use(function(socket, next) {
          sessionMiddleware(socket.request, socket.request.res || {}, next);
        });
      }
    };