-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
80 lines (66 loc) · 2.34 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
77
78
79
80
'use strict';
const hof = require('hof');
const download = require('./lib/download-file');
let settings = require('./hof.settings');
const path = require('path');
const promptSheet = require('./config').promptSheet;
const config = require('./config');
const _ = require('lodash');
const sessionCookiesTable = require('./apps/common/translations/src/en/cookies.json');
settings.routes = settings.routes.map(route => require(route));
settings.behaviours = settings.behaviours.map(require);
settings.views = path.resolve(__dirname, './apps/common/views');
settings.root = __dirname;
settings = Object.assign({}, settings, {
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);
// Downloads the offline form to client side
app.use('/prompt-sheet-for-working-offline', (req, res) => {
download.responseFile('/assets/documents', promptSheet, res);
});
const addGenericLocals = (req, res, next) => {
// Set HTML Language
res.locals.htmlLang = 'en';
// Set feedback and footer links
res.locals.feedbackUrl = '/feedback';
res.locals.footerSupportLinks = [
{ path: '/cookies', property: 'base.cookies' },
{ path: '/terms-and-conditions', property: 'base.terms' },
{ path: '/accessibility', property: 'base.accessibility' }
];
next();
};
app.use((req, res, next) => addGenericLocals(req, res, next));
app.use('/cookies', (req, res, next) => {
res.locals = Object.assign({}, res.locals, req.translate('cookies'));
res.locals['session-cookies-table'] = sessionCookiesTable['session-cookies-table'];
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;