2017-06-29 23:48:27 +02:00
|
|
|
const logger = require('winston');
|
2017-06-19 18:37:35 +02:00
|
|
|
const errorHandlers = require('../helpers/libraries/errorHandlers.js');
|
2017-06-30 07:26:29 +02:00
|
|
|
const { getAllClaims } = require('../controllers/showController.js');
|
|
|
|
const { getStatsSummary, postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
2017-06-13 20:00:50 +02:00
|
|
|
|
2017-06-30 02:10:14 +02:00
|
|
|
function sendAnalyticsAndLog (ip, originalUrl) {
|
|
|
|
// google analytics
|
|
|
|
sendGoogleAnalytics('show', ip, originalUrl);
|
|
|
|
// logging
|
|
|
|
logger.verbose(`POST request on ${originalUrl} from ${ip}`);
|
|
|
|
// get and serve the content
|
|
|
|
}
|
|
|
|
|
2017-06-28 05:25:36 +02:00
|
|
|
module.exports = (app) => {
|
2017-06-29 23:34:23 +02:00
|
|
|
// route to show the meme-fodder meme maker
|
2017-06-30 02:10:14 +02:00
|
|
|
app.get('/meme-fodder/play', ({ ip, originalUrl }, res) => {
|
|
|
|
sendAnalyticsAndLog(ip, originalUrl);
|
|
|
|
// get and render the content
|
2017-06-30 07:26:29 +02:00
|
|
|
getAllClaims('meme-fodder')
|
2017-06-21 02:39:41 +02:00
|
|
|
.then(orderedFreePublicClaims => {
|
2017-06-29 23:34:23 +02:00
|
|
|
postToStats('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-29 23:34:23 +02:00
|
|
|
// route to show statistics for spee.ch
|
2017-06-30 02:10:14 +02:00
|
|
|
app.get('/stats', ({ ip, originalUrl }, res) => {
|
|
|
|
sendAnalyticsAndLog(ip, originalUrl);
|
|
|
|
// get and render the content
|
2017-06-30 07:26:29 +02:00
|
|
|
getStatsSummary()
|
2017-06-29 23:34:23 +02:00
|
|
|
.then(result => {
|
|
|
|
postToStats('show', originalUrl, ip, 'success');
|
|
|
|
res.status(200).render('statistics', result);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
errorHandlers.handleRequestError(error, res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// route to display all free public claims at a given name
|
2017-06-30 02:10:14 +02:00
|
|
|
app.get('/:name/all', ({ ip, originalUrl, params }, res) => {
|
|
|
|
sendAnalyticsAndLog(ip, originalUrl);
|
|
|
|
// get and render the content
|
2017-06-30 07:26:29 +02:00
|
|
|
getAllClaims(params.name)
|
2017-06-17 22:51:30 +02:00
|
|
|
.then(orderedFreePublicClaims => {
|
2017-06-29 23:34:23 +02:00
|
|
|
postToStats('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
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|