All files / src index.ts

30.3% Statements 10/33
16.67% Branches 2/12
22.22% Functions 2/9
30.3% Lines 10/33
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  1x 1x 1x 1x 1x         1x 1x 1x               1x                             1x                          
 
export function HandleKoaSession2 (app: any, store: any, key?: string) {
    key = key || 'koa:sess';
    return async function(socket: any, next: any) {
        console.log('1');
        Iif (!socket.handshake.headers.cookie) {
            console.log('nnnnnn');
            return next(new Error('no cookie'));
        }
        // console.log('2', app);
        let ctx = app.createContext(socket.request, socket.response);
        console.log('3', ctx);
        let sid = ctx.cookies.get(key);
        socket.getSession = () => {
            return store.get(sid);
        };
        return next();
    };
}
 
export function HandleKoaGenericSession (app: any, store: any, key?: string) {
    key = key || 'koa.sid';
    return async function(socket: any, next: any) {
        if (!socket.handshake.headers.cookie) {
            return next(new Error('no cookie'));
        }
        let ctx = app.createContext(socket.request, socket.response);
        let sid = ctx.cookies.get(key);
        socket.getSession = () => {
            return store.get('koa:sess:' + sid);
        };
        return next();
    };
}
 
export function HandleKoaSession (app: any, store: any, key?: string) {
    key = key || 'koa:sess';
    return async function(socket: any, next: any) {
        if (!socket.handshake.headers.cookie) {
            return next(new Error('no cookie'));
        }
        let ctx = app.createContext(socket.request, socket.response);
        let sid = ctx.cookies.get(key);
        socket.getSession = () => {
            return store.get(sid);
        };
        return next();
    };
}