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) //此處打印是有 結(jié)構(gòu)的
ctx.body = {
result: res
}
}但是接口報 -- 404
3 回答

慕碼人2483693
TA貢獻(xiàn)1860條經(jīng)驗 獲得超9個贊
先把你的所有回調(diào)轉(zhuǎn)成promise
await 剛才轉(zhuǎn)的promise
await next()
- 3 回答
- 0 關(guān)注
- 4636 瀏覽
添加回答
舉報
0/150
提交
取消