koa2,ctx.body没起作用怎么回事?

https://img1.mukewang.com/5b5d53be0001d69104450038.jpg

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
    } 
}

但是接口报 -- 404


繁星coding
浏览 4500回答 3
3回答

浅唱姩華

请问 这个问题解决了吗

MMMHUHU

return next()

慕码人2483693

先把你的所有回调转成promiseawait 刚才转的promiseawait next()
打开App,查看更多内容
随时随地看视频慕课网APP