2018-04-22 15:33:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const passport = require('../lib/passport');
|
|
|
|
const clientHelpers = require('../lib/client-helpers');
|
2018-05-09 02:07:01 +00:00
|
|
|
const { getTrustedUrl } = require('../lib/urls');
|
2018-11-18 14:38:52 +00:00
|
|
|
const { AppType } = require('../../shared/app');
|
2018-04-22 15:33:43 +00:00
|
|
|
|
|
|
|
const routerFactory = require('../lib/router-async');
|
|
|
|
|
2019-04-22 00:41:40 +00:00
|
|
|
async function getRouter(appType) {
|
2018-04-22 15:33:43 +00:00
|
|
|
const router = routerFactory.create();
|
|
|
|
|
2018-09-18 08:30:13 +00:00
|
|
|
if (appType === AppType.TRUSTED) {
|
2018-04-22 15:33:43 +00:00
|
|
|
router.getAsync('/*', passport.csrfProtection, async (req, res) => {
|
2018-09-18 08:30:13 +00:00
|
|
|
const mailtrainConfig = await clientHelpers.getAnonymousConfig(req.context, appType);
|
2018-04-22 15:33:43 +00:00
|
|
|
if (req.user) {
|
|
|
|
Object.assign(mailtrainConfig, await clientHelpers.getAuthenticatedConfig(req.context));
|
|
|
|
}
|
|
|
|
|
|
|
|
res.render('root', {
|
|
|
|
reactCsrfToken: req.csrfToken(),
|
2018-05-09 02:07:01 +00:00
|
|
|
mailtrainConfig: JSON.stringify(mailtrainConfig),
|
|
|
|
scriptFiles: [
|
2019-01-05 22:56:16 +00:00
|
|
|
getTrustedUrl('client/root.js')
|
2018-12-27 13:42:21 +00:00
|
|
|
],
|
|
|
|
publicPath: getTrustedUrl()
|
2018-04-22 15:33:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return router;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-18 08:30:13 +00:00
|
|
|
module.exports.getRouter = getRouter;
|