spee.ch/routes/show-routes.js

36 lines
1.3 KiB
JavaScript
Raw Normal View History

const errorHandlers = require('../helpers/libraries/errorHandlers.js');
const showController = require('../controllers/showController.js');
const logger = require('winston');
2017-06-13 20:00:50 +02:00
module.exports = (app, ua, googleAnalyticsId) => {
2017-06-20 07:37:36 +02:00
// route to fetch all free public claims
2017-06-21 01:49:33 +02:00
app.get('/meme-fodder/play', ({ originalUrl }, res) => {
2017-06-21 02:39:41 +02:00
// google analytics
2017-06-20 07:37:36 +02:00
logger.debug(`GET request on ${originalUrl}`);
2017-06-21 02:39:41 +02:00
// get and serve content
showController
2017-06-21 18:14:53 +02:00
.getAllClaims('meme-fodder')
2017-06-21 02:39:41 +02:00
.then(orderedFreePublicClaims => {
res.status(200).render('memeFodder', { claims: orderedFreePublicClaims });
})
.catch(error => {
errorHandlers.handleRequestError(error, res);
});
2017-06-20 07:37:36 +02:00
});
// route to fetch all free public claims
app.get('/:name/all', ({ originalUrl, params }, res) => {
2017-06-20 04:34:34 +02:00
logger.debug(`GET request on ${originalUrl}`);
// google analytics
ua(googleAnalyticsId, { https: true }).event('Show Routes', '/name/all', `${params.name}/all`).send();
2017-06-21 02:39:41 +02:00
// get and serve content
showController
.getAllClaims(params.name)
.then(orderedFreePublicClaims => {
res.status(200).render('allClaims', { claims: orderedFreePublicClaims });
})
.catch(error => {
errorHandlers.handleRequestError(error, res);
});
});
};