-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
77 lines (63 loc) · 2 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
/* eslint no-process-env: 0 */
'use strict';
const hof = require('hof');
const config = require('./config');
const mockAPIs = require('./mock-apis');
const bodyParser = require('busboy-body-parser');
if (process.env.REDIS_URL) {
config.redis = process.env.REDIS_URL;
}
let settings = require('./hof.settings');
settings = Object.assign({}, settings, {
behaviours: settings.behaviours.map(require),
routes: settings.routes.map(require),
redis: config.redis,
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'
]
},
getCookies: false,
getTerms: true,
getAccessibility: false
});
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 and common directory
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('/report', (req, res) => {
res.redirect(301, '/');
});
if (config.useMocks) {
app.use(mockAPIs);
}
app.use((req, res, next) => {
// Set HTML Language
res.locals.htmlLang = 'en';
// Set feedback url, required to display phase banner
res.locals.feedbackUrl = config.feedbackUrl;
// Below can be removed once generic accessibility footer link is added to HOF
res.locals.footerSupportLinks = [
{ path: '/cookies', property: 'base.cookies' },
{ path: '/terms-and-conditions', property: 'base.terms' },
{ path: '/accessibility', property: 'base.accessibility' }
];
next();
});
app.use(bodyParser({limit: config.upload.maxFileSize}));
module.exports = app;