Koa2,ctx.body didn't work. What happened?

clipboard.png

var jwt = require("jsonwebtoken")
module.exports = async function (ctx, next) {
    const token = ctx.request.body.token || ctx.query.token || ctx.request.headers["x-access-token"]
    if(token) {
        jwt.verify(token, "zhiyuJS", function(err, decoded) {
            if (err) {
                return ctx.body = { status: 0, msg: "token", err }
            } else {
                ctx.userinfo = decoded
                next()
            }
        })
    } else {
        return ctx.body = {
            status: 0,
            msg: "token" 
        }
    }
}
exports.find = async function (ctx) {
    let res = await SpaceModel.find()
    console.log(res)  // 
    ctx.body = {
        result: res
    } 
}

but the interface report-- 404

Mar.29,2021

return next ()


  1. convert all your callbacks to promise
  2. first.
  3. the promise that await just transferred
  4. await next ()

have you solved it? I use this token for the same reason as you.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3f325-44814.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3f325-44814.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?