spee.ch/routes/home-routes.js

26 lines
888 B
JavaScript
Raw Normal View History

const logger = require('winston');
2017-06-30 07:26:29 +02:00
const { postToStats, sendGoogleAnalytics } = 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) => {
// google analytics
sendGoogleAnalytics('serve', ip, originalUrl);
// 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
// google analytics
sendGoogleAnalytics('serve', ip, originalUrl);
// 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');
});
};