app.js 876 Bytes
/**
 * 
 * @
 */

'use strict';

import http from 'http';
import Koa from 'koa';
import mount from 'koa-mount';
import serve from 'koa-static';
import body from './middleware/yoho-koa-body';
import convert from 'koa-convert';
import session from 'koa-session';
import Socket from 'socket.io';

import config from './config/config';
import webApp from './apps/web';
import ws from './lib/ws';


const port = process.env.PORT || config.port;

const app = new Koa();
const server = http.createServer(app.callback());
const io = new Socket(server);
ws.init(io);

app.keys = ['yoho-node-ci secret'];
app.use(serve(__dirname + '/public'));
app.use(convert(session({}, app)));
app.use(convert(body({
    multipart: true,
    queryString: {
        plainObjects: true
    }
})));
app.use(mount('/', webApp));

server.listen(port, () => {
    console.log(`app started in ${port}`);
});