25 lines
888 B
JavaScript
25 lines
888 B
JavaScript
const logger = require('winston');
|
|
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
|
|
|
module.exports = app => {
|
|
// route for the home page
|
|
app.get('/', ({ headers, ip, originalUrl }, res) => {
|
|
// google analytics
|
|
sendGoogleAnalytics('serve', ip, originalUrl);
|
|
// logging
|
|
logger.verbose(`GET request on ${originalUrl} from ${ip}`);
|
|
// 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) => {
|
|
// google analytics
|
|
sendGoogleAnalytics('serve', ip, originalUrl);
|
|
// logging
|
|
logger.error(`Get request on ${originalUrl} from ${ip} which was a 404`);
|
|
// post to stats
|
|
postToStats('show', originalUrl, ip, 'Error: 404');
|
|
// send response
|
|
res.status(404).render('fourOhFour');
|
|
});
|
|
};
|