|
|
@@ -0,0 +1,21 @@
|
|
|
+function setup({ db, yup, log }) {
|
|
|
+ return {
|
|
|
+ type: 'post',
|
|
|
+ route: '/goodbye',
|
|
|
+ handler(req, res, next) {
|
|
|
+ const contentPath = ['visits', req.body.name];
|
|
|
+ db.get(contentPath, reply => {
|
|
|
+ const visits = reply >= 0 ? Number(reply) + 1 : 1;
|
|
|
+ log.info(`Visited by ${req.body.name}.`);
|
|
|
+ res.send(`hello ${req.body.name}. You have visited ${visits} times.`);
|
|
|
+ db.set(contentPath, visits);
|
|
|
+ next();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ schema: yup.object().shape({
|
|
|
+ name: yup.string().required(),
|
|
|
+ }),
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+export default setup;
|