function routeFactory({ db, yup, log }) { return { verb: 'get', path: '/hello/:name', handler(req, res, next) { const contentPath = ['visits', req.params.name]; db.get(contentPath, reply => { const visits = reply >= 0 ? Number(reply) + 1 : 1; log.info(`Visited by ${req.params.name}.`); res.send(`hello ${req.params.name}. You have visited ${visits} times.`); next(); db.set(contentPath, visits); }); }, schema: yup.object().shape({ name: yup.string().required(), }), }; } export default routeFactory;