text: import Koa from 'koa'
  import json from 'koa-json'
  import bodyParser from 'koa-bodyparser'
  import convert from 'koa-convert'
  import logger from 'koa-logger'
  import views from 'koa-views'
  import serve from 'koa-static'
  import send from 'koa-send'
  import cors from 'kcors'
  
  import index from './router/index'
  import api from './router/api'
  import test from './router/test'
  import login from './router/login'
  
  import mysql from './lib/mysql';
  import authorize from './lib/authorize';
  
  const app = new Koa();
  app.keys = ['cookie-secert'];
  
  // 全局错误处理
  app.use(async(ctx, next) => {
      try {
          await next()
      } catch (err) {
          ctx.body = {
              message: err.message
          }
          ctx.status = err.status || 500
      }
  });
  
  //设置header头
  app.use( convert( cors({
      // origin: '*',
      credentials: true,
      headers: ['Content-Type, Content-Length, Authorization, Accept, X-Requested-With'],
      methods: ['PUT, POST, GET, DELETE, OPTIONS']
  }) ) );
  
  //设置DBModel
  app.use(async(ctx, next) => {
      ctx.DBModel = mysql;
      await next();
  });
  
  // 记录所用方式与时间
  app.use(convert(logger()));
  
  // 传输JSON
  app.use(convert(json()));
  
  // body解析
  app.use(convert(bodyParser()));
  
  // 设置渲染引擎
  app.use(views(__dirname + '/views', {
      extension: 'ejs'
  }));
  
  // 静态文件夹
  app.use(convert(serve(__dirname)));
  
  // 发送文件，如HTML
  app.use(async(ctx, next) => {
      ctx.send = send;
      await next();
  });
  
  // 路由
  app
      .use(login.routes())
      .use(index.routes())
      .use(api.routes())
      .use(test.routes());
  
  app.listen(3000)
  
  console.log(`Server up and running! On port 3000!`);