i have a route like this
router.post('/policy', async (req, res, next) => {
try {
console.log(req.body);
} catch (e) {
console.log(e)
res.sendStatus(500)
}
})
I want the same logic to be executed when /role
is called what is the correct way to do this ? ( preferrably without copy pasting the same code )
I can think of this logic
router.post('/policy', async (req, res, next) => {
try {
console.log(req.body);
} catch (e) {
console.log(e)
res.sendStatus(500)
}
})
router.post('/role', async (req, res, next) => {
try {
console.log(req.body);
} catch (e) {
console.log(e)
res.sendStatus(500)
}
})
Why am i naming the routes differently for same logic ?
Because i want the back-end to be more read-able and specific to what task it is doing i.e adding policy OR role