2017-06-19 22:10:06 +02:00
|
|
|
const logger = require('winston');
|
2017-07-12 01:55:03 +02:00
|
|
|
const { postToStats, getTrendingClaims } = require('../controllers/statsController.js');
|
|
|
|
const errorHandlers = require('../helpers/libraries/errorHandlers.js');
|
2017-06-19 22:10:06 +02:00
|
|
|
|
2017-06-17 22:51:30 +02:00
|
|
|
module.exports = app => {
|
|
|
|
// route for the home page
|
2017-06-30 02:10:14 +02:00
|
|
|
app.get('/', ({ headers, ip, originalUrl }, res) => {
|
2017-07-12 01:55:03 +02:00
|
|
|
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);
|
|
|
|
});
|
2017-06-19 18:37:35 +02:00
|
|
|
});
|
2017-06-17 22:51:30 +02:00
|
|
|
// a catch-all route if someone visits a page that does not exist
|
2017-06-28 00:53:53 +02:00
|
|
|
app.use('*', ({ originalUrl, ip }, res) => {
|
2017-07-06 22:37:03 +02:00
|
|
|
logger.error(`404 on ${originalUrl}`);
|
2017-06-30 02:10:14 +02:00
|
|
|
// post to stats
|
2017-07-12 01:55:03 +02:00
|
|
|
postToStats('show', originalUrl, ip, null, null, null, null, null, 'Error: 404');
|
2017-06-30 02:10:14 +02:00
|
|
|
// send response
|
2017-06-19 18:37:35 +02:00
|
|
|
res.status(404).render('fourOhFour');
|
|
|
|
});
|
|
|
|
};
|