homepage.js/routes/guestbook.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-02-19 06:30:02 +01:00
const Helpers = require('../helpers');
2023-02-19 08:07:44 +01:00
async function handler(req, res, next) {
try {
res.send(await Helpers.ViewLoader.load('guestbook.pug', {
current_route: req.originalUrl,
ip: req.ip,
data: {
// TODO: load from db
1: {
name: 'John Doe',
email: 'a@b.c',
text: 'hiiii',
hidemail: false,
ip: '0.0.0.0',
hidden: false,
time: Date.now()
}
}
}));
return;
} catch (err) {
next(err);
}
2023-02-19 06:30:02 +01:00
}
2023-02-19 07:05:36 +01:00
async function submit(req, res) {
2023-02-19 08:07:44 +01:00
const { name, email, message } = req.body;
const hidemail = req.body.hidemail ? (req.body.hidemail == 'on' ? true : false) : false;
res.send({
name, email, message, hidemail
});
2023-02-19 07:05:36 +01:00
return;
}
2023-02-19 06:30:02 +01:00
module.exports = (router) => {
router.get('/guestbook', handler);
2023-02-19 07:05:36 +01:00
router.post('/guestbook/submit', submit);
2023-02-19 06:30:02 +01:00
}