mailtrain/routes/index.js
Tomas Bures 63765f7222 Client's public folder renamed to static
Regular campaign sender seems to have most of the code in place. (Not tested.)
2018-09-18 10:30:13 +02:00

36 lines
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 { AppType } = require('../shared/app');
const routerFactory = require('../lib/router-async');
function getRouter(appType) {
const router = routerFactory.create();
if (appType === AppType.TRUSTED) {
router.getAsync('/*', passport.csrfProtection, async (req, res) => {
const mailtrainConfig = await clientHelpers.getAnonymousConfig(req.context, appType);
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 = getRouter;