index.js 796 B

123456789101112131415161718192021222324252627282930313233343536
  1. const router = require('koa-router')()
  2. const UserDao = require('../dao/UserDao')
  3. const crypto = require('crypto')
  4. router.get('/', async (ctx, next) => {
  5. await ctx.render('index', {
  6. title: 'Hello Koa 2!'
  7. })
  8. ctx.body = {
  9. code: 0,
  10. msg: 'Hello'
  11. }
  12. })
  13. router.get('/string', async (ctx, next) => {
  14. ctx.body = 'koa2 string'
  15. })
  16. router.get('/json', async (ctx, next) => {
  17. ctx.body = {
  18. title: 'koa2 json'
  19. }
  20. })
  21. router.get('/test', async (ctx, next) => {
  22. // let user = await UserDao.selectById(1)
  23. // let dataString = JSON.stringify(user)
  24. // let data = JSON.parse(dataString)
  25. // console.log(data[0].user_name)
  26. ctx.body = crypto.createHash('md5').update('123').digest('hex') // 对密码进行md5 数据库中保存的是md5后的密码
  27. })
  28. module.exports = router