问题代码
1 | router.post('/signup', async (ctx, next) => { |
上面的代码不行, postman中总是会显示 404 not found
然后尝试了
1 | let code |
也不行, 打印一直是 undefined
后来有在网上看到 let res = await newUser.save()
的写法, 但是koa会报错.
解决方法
花了一天时间, 终于想到可以用try catch来解决这个问题
1 | router.post('/signup', async (ctx, next) => { |
这样终于可以在 postman 中正确的返回body了!