我对 javascript、nodejs 和express 很陌生,并且对使用next().
我希望我的代码转移到下一个路由器next(),但它似乎转移到下一个then。
我的代码:
//validation
router.post('/requests', (req, res, next) => {
let {myData} = req.body
basicCheck(res, cluster, myData)
.then(() => {
if (myCheck()) {
next()
return // Doesn't need to do rest of the code. Just move on to the next router.post
}
...
return Promise.all(somePromises)
})
.then(() => {
...
return Promise.all(somePromises)
})
.then(() => {
if (someCheck() {
next()
} else {
res.status(400).send('message') // My code reaches here! even when myCheck() is true
}
})
.catch((err) => {
...
})
})
// where next() needs to be
router.post('/requests', (req, res) => {
...
})
当next()在 之外时basicCheck,next()转到下一个 router.post。
我不明白哪里指示的概念next()。
myCheck()在内部执行操作时如何更正此代码basicCheck()?
慕的地8271018
相关分类