spee.ch/routes/home-routes.js

27 lines
956 B
JavaScript
Raw Normal View History

const logger = require('winston');
const { postToStats, getTrendingClaims } = require('../controllers/statsController.js');
const errorHandlers = require('../helpers/libraries/errorHandlers.js');
module.exports = app => {
// route for the home page
2017-06-30 02:10:14 +02:00
app.get('/', ({ headers, ip, originalUrl }, res) => {
const startDate = new Date();
startDate.setDate(startDate.getDate() - 1);
getTrendingClaims(startDate)
.then(result => {
res.status(200).render('index', { trendingAssets: result });
})
.catch(error => {
errorHandlers.handleRequestError(error, res);
});
});
// a catch-all route if someone visits a page that does not exist
app.use('*', ({ originalUrl, ip }, res) => {
logger.error(`404 on ${originalUrl}`);
2017-06-30 02:10:14 +02:00
// post to stats
postToStats('show', originalUrl, ip, null, null, null, null, null, 'Error: 404');
2017-06-30 02:10:14 +02:00
// send response
res.status(404).render('fourOhFour');
});
};