2018-09-22 16:12:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const router = require('../lib/router-async').create();
|
2019-07-05 21:23:02 +00:00
|
|
|
const messageSender = require('../lib/message-sender');
|
2018-09-22 16:12:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
router.get('/:campaign/:list/:subscription', (req, res, next) => {
|
2019-07-05 21:23:02 +00:00
|
|
|
messageSender.getMessage(req.params.campaign, req.params.list, req.params.subscription)
|
2018-09-22 16:12:22 +00:00
|
|
|
.then(result => {
|
|
|
|
const {html} = result;
|
|
|
|
|
2018-09-27 10:34:54 +00:00
|
|
|
if (html.match(/<\/body\b/i)) {
|
|
|
|
res.render('partials/tracking-scripts', {
|
|
|
|
layout: 'archive/layout-raw'
|
|
|
|
}, (err, scripts) => {
|
|
|
|
if (err) {
|
|
|
|
return next(err);
|
|
|
|
}
|
2018-09-29 20:07:24 +00:00
|
|
|
const htmlWithScripts = scripts ? html.replace(/<\/body\b/i, match => scripts + match) : html;
|
2018-09-27 10:34:54 +00:00
|
|
|
|
|
|
|
res.render('archive/view', {
|
|
|
|
layout: 'archive/layout-raw',
|
2018-09-29 20:07:24 +00:00
|
|
|
message: htmlWithScripts
|
2018-09-27 10:34:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
res.render('archive/view', {
|
|
|
|
layout: 'archive/layout-wrapped',
|
2018-09-22 16:12:22 +00:00
|
|
|
message: html
|
|
|
|
});
|
2018-09-27 10:34:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-22 16:12:22 +00:00
|
|
|
})
|
|
|
|
.catch(err => next(err));
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|