Answer the question
In order to leave comments, you need to log in
Node.js how to exit an application?
I have an endpoint. And two callbacks below.
router.put('/fixtures/change/main/:fixtoId', jwtTokenUserRole,ChangeMainFixture )
exports.jwtTokenUserRole = async (req, res,next) =>{
let head = req.headers
var token = head.authorization.replace('Bearer ','')
let j = jwt.decode(token)
req.auth = j.role
next()
}
exports.ChangeMainFixture = (req,res) =>{
let fixMain = req.fixtur
fixMain = _.extend(fixMain, req.body)
fixMain.save((err, result) => {
if (err) {
return res.status(400).json({
error: err
})
}
res.json(result)
})
}
Answer the question
In order to leave comments, you need to log in
There is such a thing as middleware, an intermediary that will cut off for the necessary routes according to the desired condition (which is the admin). Write once and add it to the routes, while the elbow - to the route it will come if other layers are skipped.
https://expressjs.com/en/guide/using-middleware.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question