mailtrain/server/routes/archive.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict';
const router = require('../lib/router-async').create();
const messageSender = require('../lib/message-sender');
router.get('/:campaign/:list/:subscription', (req, res, next) => {
messageSender.getMessage(req.params.campaign, req.params.list, req.params.subscription)
.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);
}
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',
message: htmlWithScripts
2018-09-27 10:34:54 +00:00
});
});
} else {
res.render('archive/view', {
layout: 'archive/layout-wrapped',
message: html
});
2018-09-27 10:34:54 +00:00
}
})
.catch(err => next(err));
});
module.exports = router;