server.js 697 B

12345678910111213141516171819202122232425262728293031
  1. import Koa from 'koa'
  2. import logger from 'koa-logger'
  3. import convert from 'koa-convert'
  4. import bodyParser from 'koa-bodyparser'
  5. import config from '../config'
  6. //建立MYSQL连接
  7. require('../src/new_dao');
  8. // require('../src/old_dao');
  9. require('../src/old_dao2');
  10. // require('../src/test_dao');
  11. //创建Koa对象
  12. const app = new Koa()
  13. //加载中间件
  14. app.use(convert(logger()))
  15. app.use(convert(bodyParser()))
  16. //加载路由
  17. require('../src/modules')(app)
  18. //接入Socket.IO
  19. const server = require('http').createServer(app.callback());
  20. console.log('config', config)
  21. //启动服务
  22. server.listen(config.port, () => {
  23. console.log(`Server started on ${config.port}`)
  24. });
  25. export default app