spee.ch/routes/home-routes.js

22 lines
717 B
JavaScript
Raw Normal View History

const logger = require('winston');
2017-07-05 17:13:01 +02:00
const { postToStats } = require('../controllers/statsController.js');
module.exports = app => {
// route for the home page
2017-06-30 02:10:14 +02:00
app.get('/', ({ headers, ip, originalUrl }, res) => {
// logging
2017-06-29 21:35:36 +02:00
logger.verbose(`GET request on ${originalUrl} from ${ip}`);
2017-06-30 02:10:14 +02:00
// send response
res.status(200).render('index');
});
// a catch-all route if someone visits a page that does not exist
app.use('*', ({ originalUrl, ip }, res) => {
2017-06-30 02:10:14 +02:00
// logging
logger.error(`Get request on ${originalUrl} from ${ip} which was a 404`);
2017-06-30 02:10:14 +02:00
// post to stats
postToStats('show', originalUrl, ip, 'Error: 404');
// send response
res.status(404).render('fourOhFour');
});
};