spee.ch/routes/show-routes.js
2017-06-21 09:14:53 -07:00

35 lines
1.3 KiB
JavaScript

const errorHandlers = require('../helpers/libraries/errorHandlers.js');
const showController = require('../controllers/showController.js');
const logger = require('winston');
module.exports = (app, ua, googleAnalyticsId) => {
// route to fetch all free public claims
app.get('/meme-fodder/play', ({ originalUrl }, res) => {
// google analytics
logger.debug(`GET request on ${originalUrl}`);
// get and serve content
showController
.getAllClaims('meme-fodder')
.then(orderedFreePublicClaims => {
res.status(200).render('memeFodder', { claims: orderedFreePublicClaims });
})
.catch(error => {
errorHandlers.handleRequestError(error, res);
});
});
// route to fetch all free public claims
app.get('/:name/all', ({ originalUrl, params }, res) => {
logger.debug(`GET request on ${originalUrl}`);
// google analytics
ua(googleAnalyticsId, { https: true }).event('Show Routes', '/name/all', `${params.name}/all`).send();
// get and serve content
showController
.getAllClaims(params.name)
.then(orderedFreePublicClaims => {
res.status(200).render('allClaims', { claims: orderedFreePublicClaims });
})
.catch(error => {
errorHandlers.handleRequestError(error, res);
});
});
};