2024-06-22 08:09:40 -04:00
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const fs = require('fs')
|
|
|
|
|
|
|
|
const file = './messages'
|
|
|
|
|
|
|
|
const get = (res, thankYou) => {
|
|
|
|
res.render('index', { title: 'Message Sage 😎', thankYou });
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GET home page. */
|
|
|
|
router.get('/', function(req, res, next) {
|
|
|
|
get(res, false)
|
|
|
|
});
|
|
|
|
|
|
|
|
router.post('/', (req, res) => {
|
|
|
|
const log = { message: req.body.message, timestamp: new Date() }
|
2024-06-22 08:17:54 -04:00
|
|
|
fs.appendFileSync(file, JSON.stringify(log) + '\n')
|
2024-06-22 08:09:40 -04:00
|
|
|
|
|
|
|
get(res, true)
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = router;
|