mailtrain/routes/index.js
Tomas Bures 7788b0bc67 Fixed sandbox. Multiple tabs work now.
WiP on selectable mosaico templates.

TODO: Make files always point to trusted URL, such that we don't have to rebase them. They are public anyway. The same goes for mosaico endpoints: /mosaico/templates and /mosaico/img
2018-05-09 04:07:01 +02:00

37 lines
No EOL
1.1 KiB
JavaScript

'use strict';
const passport = require('../lib/passport');
const _ = require('../lib/translate')._;
const clientHelpers = require('../lib/client-helpers');
const { getTrustedUrl } = require('../lib/urls');
const routerFactory = require('../lib/router-async');
function getRouter(trusted) {
const router = routerFactory.create();
if (trusted) {
router.getAsync('/*', passport.csrfProtection, async (req, res) => {
const mailtrainConfig = await clientHelpers.getAnonymousConfig(req.context, trusted);
if (req.user) {
Object.assign(mailtrainConfig, await clientHelpers.getAuthenticatedConfig(req.context));
}
res.render('root', {
reactCsrfToken: req.csrfToken(),
mailtrainConfig: JSON.stringify(mailtrainConfig),
scriptFiles: [
getTrustedUrl('mailtrain/common.js'),
getTrustedUrl('mailtrain/root.js')
]
});
});
}
return router;
}
module.exports = {
getRouter
};