spee.ch/routes/home-routes.js

27 lines
908 B
JavaScript
Raw Normal View History

2017-07-13 09:19:59 +02:00
const { postToStats, getTrendingClaims } = require('../controllers/statsController.js');
2017-08-03 02:13:02 +02:00
const errorHandlers = require('../helpers/errorHandlers.js');
module.exports = app => {
// route for the home page
2017-06-30 02:10:14 +02:00
app.get('/', ({ headers, ip, originalUrl }, res) => {
2017-07-13 09:19:59 +02:00
// get yesterday's date
const startDate = new Date();
startDate.setDate(startDate.getDate() - 3);
2017-07-12 03:17:38 +02:00
// send response
2017-07-13 09:19:59 +02:00
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
2017-08-04 06:59:22 +02:00
app.use('*', ({ headers, originalUrl, ip }, res) => {
2017-06-30 02:10:14 +02:00
// post to stats
2017-07-13 00:30:31 +02:00
postToStats('show', originalUrl, ip, null, null, 'Error: 404');
2017-06-30 02:10:14 +02:00
// send response
res.status(404).render('fourOhFour');
});
};