const Koa = require('koa') const config = require('./config') const path = require('path') const app = new Koa() // load koa middleware const koaLogger = require('koa-morgan') const koaSession = require('koa-session2') const rootRouter = require('./route') const koaRender = require('koa-ejs') // set middleware app.use(koaLogger('dev')) app.use(koaSession()) app.use(rootRouter.allowedMethods()) app.use(rootRouter.routes()) koaRender(app, { root: path.join(__dirname, 'views'), layout: 'template', viewExt: 'ejs', cache: false, debug: false }) const server = app.listen(config.port, () => { console.log(`server start on port ${server.address().port}`) }) module.exports = server