-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
76 lines (63 loc) · 2.15 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const hof = require('hof');
const config = require('./config');
const _ = require('lodash');
const path = require('path');
let settings = require('./hof.settings');
settings = Object.assign({}, settings, {
behaviours: settings.behaviours.map(require),
routes: settings.routes.map(require),
views: settings.views.map(view => path.resolve(__dirname, view)),
getTerms: false,
getCookies: false,
csp: {
imgSrc: [
'www.google-analytics.com',
'ssl.gstatic.com',
'www.google.co.uk/ads/ga-audiences'
],
connectSrc: [
'https://www.google-analytics.com',
'https://region1.google-analytics.com',
'https://region1.analytics.google.com'
]
}
});
const app = hof(settings);
// Terms & Cookies added to have visibility on accessibility statement
// in the footer. Once HOF has updated with that we can remove these
// including the getTerms: false, getCookies: false config
app.use('/terms-and-conditions', (req, res, next) => {
res.locals = Object.assign({}, res.locals, req.translate('terms'));
next();
});
app.use('/cookies', (req, res, next) => {
res.locals = Object.assign({}, res.locals, req.translate('cookies'));
next();
});
app.use((req, res, next) => {
res.locals.htmlLang = 'en';
res.locals.feedbackUrl = '/feedback';
res.locals.footerSupportLinks = [
{ path: '/cookies', property: 'base.cookies' },
{ path: '/terms-and-conditions', property: 'base.terms' },
{ path: '/accessibility', property: 'base.accessibility' },
{ path: '/improve-our-services', property: 'base.improve-our-services' }
];
next();
});
if (config.nodeEnv === 'development' || config.nodeEnv === 'test') {
app.use('/test/bootstrap-session', (req, res) => {
const appName = req.body.appName;
if (!_.get(req, 'session[`hof-wizard-${appName}`]')) {
if (!req.session) {
throw new Error('Redis is not running!');
}
req.session[`hof-wizard-${appName}`] = {};
}
Object.keys(req.body.sessionProperties || {}).forEach(key => {
req.session[`hof-wizard-${appName}`][key] = req.body.sessionProperties[key];
});
res.send('Session populate complete');
});
}
module.exports = app;