How to use the koa.io function in koa

To help you get started, we’ve selected a few koa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github azproduction / node-mc / server / node-mc.js View on Github external
_startServer() {
        var args = this.args;
        var {port, host} = this.args;
        var app = koa();
        routes({app, args});

        app.listen(Number(port), host);

        var clientConnect = this._clientConnect.bind(this);
        var clientDisconnect = this._clientDisconnect.bind(this);
        // Connect flux to socket.io channel
        app.io.use(function *(next) {
            clientConnect(this.socket);
            yield* next;
            clientDisconnect(this.socket);
        });
    }
github azproduction / node-mc / server / app.js View on Github external
import koa from 'koa.io';
import http from 'http';
import routes from './routes';
import Cli from './components/cli';
import TuiReact from './lib/tui-react';
import env from '../shared/env';
import ServerFlux from './flux';

var app = koa();

routes(app);

app.listen(env.PORT);

// Connect flux to socket.io channel
var flux = new ServerFlux();
app.io.use(function *(next) {
    // on connect
    flux.connect(this.socket);
    sendWindowSize();
    yield* next;
    // on disconnect
    flux.disconnect(this.socket);
});
github azproduction / node-mc / server / routes / views / index.js View on Github external
export default function createViews(args) {
    var app = koa();

// Add jade rendering
    app.use(views(__dirname, {
        cache: true,
        default: 'jade'
    }));

    app.use(router(app));

    app.get('/', function *() {
        yield this.render('index', {
            title: 'mc',
            env: {
                NODE_ENV: args.nodeEnv
            }
        });
github azproduction / node-mc / server / routes / api / index.js View on Github external
export default function api() {
    var app = koa();

    app.use(json());
    app.use(router(app));

    app.get('/ls', function *() {
        var dirName = this.query.dir_name || process.cwd();
        if (dirName === '~') {
            dirName = homedir();
        }
        this.body = ls(dirName);
    });

    app.get('/cat', function *() {
        this.body = cat(this.query.file_name);
    });

koa

Koa web app framework

MIT
Latest version published 7 months ago

Package Health Score

93 / 100
Full package analysis