-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
62 lines (50 loc) · 1.43 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
'use strict';
const hof = require('hof');
const config = require('./config');
const mockPostcode = require('./mock-postcode');
const _ = require('lodash');
let settings = require('./hof.settings');
settings = Object.assign({}, settings, {
behaviours: settings.behaviours.map(require),
routes: settings.routes.map(require),
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'
]
}
});
if (config.env === 'ci') {
settings.middleware = [
mockPostcode
];
}
const app = hof(settings);
app.use((req, res, next) => {
// Set HTML Language
res.locals.htmlLang = 'en';
res.locals.feedbackUrl = config.survey.urls.root;
next();
});
if (config.env === 'development' || config.env === '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;