Skip to content

hgenru/socket-io-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

socket-io-router

koa-like socket io router

Installation

npm i --save https://github.com/hgenru/socket-io-router.git

Usage

full doc here http://hgenru.github.io/socket-io-router/0.0.1/

const co = require('co');
const IO = require('socket.io');
const Router = require('socket-io-router');

const router = new Router(io);
router.route('ping', (ctx) => ctx.success('pong'));

router.route('async', co.wrap(function*(ctx, next) {
    let data = yield queryFromDb();
    ctx.success(data);
    return next();
}));

router.route('compose-middleware', [
    co.wrap(function*(ctx, next) {
        console.log('request');
        return next();
    }),
    co.wrap(function*(ctx, next) {
        let data = yield queryFromDb();
        ctx.success(data);
        return next();
    })
]);

Releases

No releases published

Packages

No packages published