-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
54 lines (43 loc) · 1.64 KB
/
index.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
'use strict';
const hof = require('hof');
const addDynamicSettings = (settings) => {
settings.routes = settings.routes.map(route => require(route));
settings.root = __dirname;
// suppress logs when running the app in silent mode for automation testing, so app logs do not mix with test logs
if (process.argv.some(commandLineArgument => commandLineArgument === 'silent')) {
settings.loglevel = 'silent';
}
return settings;
};
const addGenericLocals = (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' },
];
return next();
};
/*
During automation test setup, we ping the app with '?automation-test' query to check it is ready before running tests.
Put a cookie on this request so it doesn't fail HOF-middleware cookie check.
*/
const addAutomationTestCookie = (req, res, next) => {
if (req.query['automation-test'] !== undefined) {
req.cookies.testCookie = 'test';
}
return next();
};
const app = hof(addDynamicSettings(require('./hof.settings')));
app.use((req, res, next) => addGenericLocals(req, res, next));
app.use('/start', (req, res, next) => addAutomationTestCookie(req, res, next));
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();
});
module.exports = app;