added trending images to homepage

This commit is contained in:
bill bittner 2017-07-13 00:19:59 -07:00
parent 476f28441c
commit d3509c5d98
2 changed files with 14 additions and 4 deletions

View file

@ -1,15 +1,23 @@
const logger = require('winston'); const { postToStats, getTrendingClaims } = require('../controllers/statsController.js');
const { postToStats } = require('../controllers/statsController.js'); const errorHandlers = require('../helpers/libraries/errorHandlers.js');
module.exports = app => { module.exports = app => {
// route for the home page // route for the home page
app.get('/', ({ headers, ip, originalUrl }, res) => { app.get('/', ({ headers, ip, originalUrl }, res) => {
// get yesterday's date
const startDate = new Date();
startDate.setDate(startDate.getDate() - 1);
// send response // send response
res.status(200).render('index'); 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 // a catch-all route if someone visits a page that does not exist
app.use('*', ({ originalUrl, ip }, res) => { app.use('*', ({ originalUrl, ip }, res) => {
logger.error(`404 on ${originalUrl}`);
// post to stats // post to stats
postToStats('show', originalUrl, ip, null, null, 'Error: 404'); postToStats('show', originalUrl, ip, null, null, 'Error: 404');
// send response // send response

View file

@ -3,7 +3,9 @@
<div class="full"> <div class="full">
{{> publish}} {{> publish}}
{{> learnMore}} {{> learnMore}}
{{> trendingAssets}}
</div> </div>
{{> footer}}
</div> </div>
<script src="/socket.io/socket.io.js"></script> <script src="/socket.io/socket.io.js"></script>