2017-06-19 18:37:35 +02:00
|
|
|
const errorHandlers = require('../helpers/libraries/errorHandlers.js');
|
|
|
|
const showController = require('../controllers/showController.js');
|
2017-06-19 22:10:06 +02:00
|
|
|
const logger = require('winston');
|
2017-06-28 08:04:47 +02:00
|
|
|
const { postToAnalytics } = require('../helpers/libraries/analytics');
|
2017-06-13 20:00:50 +02:00
|
|
|
|
2017-06-28 05:25:36 +02:00
|
|
|
module.exports = (app) => {
|
2017-06-20 07:37:36 +02:00
|
|
|
// route to fetch all free public claims
|
2017-06-28 00:53:53 +02:00
|
|
|
app.get('/meme-fodder/play', ({ originalUrl, ip }, res) => {
|
|
|
|
logger.debug(`GET request on ${originalUrl} from ${ip}`);
|
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 => {
|
2017-06-28 07:41:48 +02:00
|
|
|
postToAnalytics('show', originalUrl, ip, 'success');
|
2017-06-21 02:39:41 +02:00
|
|
|
res.status(200).render('memeFodder', { claims: orderedFreePublicClaims });
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-06-28 07:41:48 +02:00
|
|
|
errorHandlers.handleRequestError('show', originalUrl, ip, error, res);
|
2017-06-21 02:39:41 +02:00
|
|
|
});
|
2017-06-20 07:37:36 +02:00
|
|
|
});
|
2017-06-17 22:51:30 +02:00
|
|
|
// route to fetch all free public claims
|
2017-06-28 00:53:53 +02:00
|
|
|
app.get('/:name/all', ({ originalUrl, params, ip }, res) => {
|
|
|
|
logger.debug(`GET request on ${originalUrl} from ${ip}`);
|
2017-06-21 02:39:41 +02:00
|
|
|
// get and serve content
|
2017-06-17 22:51:30 +02:00
|
|
|
showController
|
|
|
|
.getAllClaims(params.name)
|
|
|
|
.then(orderedFreePublicClaims => {
|
2017-06-28 07:41:48 +02:00
|
|
|
postToAnalytics('show', originalUrl, ip, 'success');
|
2017-06-19 18:37:35 +02:00
|
|
|
res.status(200).render('allClaims', { claims: orderedFreePublicClaims });
|
2017-06-17 22:51:30 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-06-28 07:41:48 +02:00
|
|
|
errorHandlers.handleRequestError('show', originalUrl, ip, error, res);
|
2017-06-19 18:37:35 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|