index.js 453 B

12345678910111213141516171819202122
  1. const Koa = require('koa')
  2. const koaBody = require('koa-body')
  3. const send = require('koa-send')
  4. const path = require('path')
  5. const root = path.resolve(__dirname, 'public')
  6. const app = new Koa()
  7. app.use(async (ctx, next) => {
  8. console.log(`${ctx.method} ${ctx.path}`)
  9. return next()
  10. })
  11. app.use(koaBody())
  12. app.use(async (ctx) => {
  13. return send(ctx, ctx.path, { root, index: 'index.html' })
  14. })
  15. app.listen(8040)
  16. console.log('Server started')