-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
86 lines (73 loc) · 2.31 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
81
82
83
84
85
86
'use strict';
const path = require('path');
const hof = require('hof');
const bodyParser = require('busboy-body-parser');
const config = require('./config.js');
const mockAPIs = require('./mock-apis.js');
const BaseController = require('./apps/common/controllers/base');
let appName = '';
let settings = require('./hof.settings');
settings = Object.assign({}, settings, {
routes: settings.routes.map(require),
fields: path.resolve(__dirname, settings.fields),
views: settings.views.map(view => path.resolve(__dirname, view)),
baseController: BaseController,
behaviours: [superclass => class extends superclass {
_checkEmpty(req, res, next) {
next();
}
}, require('hof/components/clear-session')
],
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'
]
}
});
const app = hof(settings);
app.use((req, res, next) => {
// Set HTML Language
res.locals.htmlLang = 'en';
res.locals.appName = appName;
// Set feedback and footer links
res.locals.feedbackUrl = config.survey.urls.root;
next();
});
// set appName to appear on the cookie banner for each service
app.use('/s5', (req, res, next) => {
res.locals.appName = 'Prohibited weapons and ammunition licensing';
appName = res.locals.appName;
res.locals.feedbackUrl = config.survey.urls['new-dealer'];
next();
});
app.use('/museums', (req, res, next) => {
res.locals.appName = 'Apply for Museum Firearms Licence';
appName = res.locals.appName;
res.locals.feedbackUrl = config.survey.urls.museums;
next();
});
app.use('/shooting-clubs', (req, res, next) => {
res.locals.appName = 'Apply for Shooting Club Approval';
appName = res.locals.appName;
res.locals.feedbackUrl = config.survey.urls['shooting-clubs'];
next();
});
app.use('/supporting-documents', (req, res, next) => {
res.locals.appName = 'Submit Supporting Documents';
appName = res.locals.appName;
res.locals.feedbackUrl = config.survey.urls['supporting-documents'];
next();
});
if (!config.env || config.env === 'ci') {
app.use(mockAPIs);
}
app.use(bodyParser({limit: config.upload.maxfilesize}));
module.exports = app;