-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
122 lines (109 loc) · 6.28 KB
/
app.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const express = require('express');
const nunjucks = require('nunjucks');
const filePath = require('path');
const app = express();
const port = process.env.PORT || 3002;
const contextPath = process.env.CONTEXT_PATH || '/';
const bodyParser = require('body-parser');
const packageMeta = require('./package.json');
const authenticationMiddleware = require('./middleware/authentication');
const setVersionMiddleware = require('./middleware/versionPassthrough');
const autoStoreDataMiddleware = require('./middleware/autoStoreData');
const sessionMiddleware = require('./middleware/session');
const { handleGetRequest } = require('./middleware/handleGetRequest');
const locale = require('./middleware/locale');
const journeyType = require('./middleware/journeyType');
const actuatorRoutes = require('./routes/actuator');
const notFoundRoutes = require('./routes/errors/404');
app.set('view engine', 'njk');
app.set('views', `${__dirname}/views`);
const nunjucksEnv = nunjucks.configure([
`${__dirname}/node_modules/govuk-frontend`,
`${__dirname}/views/`,
], {
autoescape: true,
express: app,
});
nunjucksEnv.addFilter('makeArray', (value) => {
if (!Array.isArray(value)) {
return [value];
}
return value;
});
app.use(authenticationMiddleware);
app.use(contextPath, express.static(filePath.join(__dirname, '/public')));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(sessionMiddleware());
app.use(autoStoreDataMiddleware);
app.use(locale());
app.use(journeyType());
// [Journey routes] (do not edit this comment, it is used in automation)
app.use('/sprint-100/', setVersionMiddleware('/sprint-100/'), require('./routes/sprint-100'));
app.use('/sprint-99/', setVersionMiddleware('/sprint-99/'), require('./routes/sprint-99'));
app.use('/sprint-98/', setVersionMiddleware('/sprint-98/'), require('./routes/sprint-98'));
app.use('/sprint-97/', setVersionMiddleware('/sprint-97/'), require('./routes/sprint-97'));
app.use('/sprint-96/', setVersionMiddleware('/sprint-96/'), require('./routes/sprint-96'));
app.use('/sprint-95/', setVersionMiddleware('/sprint-95/'), require('./routes/sprint-95'));
app.use('/sprint-94/', setVersionMiddleware('/sprint-94/'), require('./routes/sprint-94'));
app.use('/sprint-93/', setVersionMiddleware('/sprint-93/'), require('./routes/sprint-93'));
app.use('/sprint-92/', setVersionMiddleware('/sprint-92/'), require('./routes/sprint-92'));
app.use('/sprint-91/', setVersionMiddleware('/sprint-91/'), require('./routes/sprint-91'));
app.use('/sprint-90/', setVersionMiddleware('/sprint-90/'), require('./routes/sprint-90'));
app.use('/sprint-89/', setVersionMiddleware('/sprint-89/'), require('./routes/sprint-89'));
app.use('/sprint-88/', setVersionMiddleware('/sprint-88/'), require('./routes/sprint-88'));
app.use('/sprint-87/', setVersionMiddleware('/sprint-87/'), require('./routes/sprint-87'));
app.use('/sprint-86/', setVersionMiddleware('/sprint-86/'), require('./routes/sprint-86'));
app.use('/sprint-85/', setVersionMiddleware('/sprint-85/'), require('./routes/sprint-85'));
app.use('/sprint-84/', setVersionMiddleware('/sprint-84/'), require('./routes/sprint-84'));
app.use('/sprint-83/', setVersionMiddleware('/sprint-83/'), require('./routes/sprint-83'));
app.use('/sprint-82/', setVersionMiddleware('/sprint-82/'), require('./routes/sprint-82'));
app.use('/sprint-81/', setVersionMiddleware('/sprint-81/'), require('./routes/sprint-81'));
app.use('/ur-02-2024/', setVersionMiddleware('/ur-02-2024/'), require('./routes/ur-02-2024'));
app.use('/sprint-80/', setVersionMiddleware('/sprint-80/'), require('./routes/sprint-80'));
app.use('/sprint-79/', setVersionMiddleware('/sprint-79/'), require('./routes/sprint-79'));
app.use('/sprint-78/', setVersionMiddleware('/sprint-78/'), require('./routes/sprint-78'));
app.use('/sprint-77/', setVersionMiddleware('/sprint-77/'), require('./routes/sprint-77'));
app.use('/sprint-75/', setVersionMiddleware('/sprint-75/'), require('./routes/sprint-75'));
app.use('/sprint-63/', setVersionMiddleware('/sprint-63/'), require('./routes/sprint-63'));
app.use('/sprint-62-severity/', setVersionMiddleware('/sprint-62-severity/'), require('./routes/sprint-62-severity'));
app.use('/sprint-62/', setVersionMiddleware('/sprint-62/'), require('./routes/sprint-62'));
app.use('/sprint-61-1/', setVersionMiddleware('/sprint-61-1/'), require('./routes/sprint-61-1'));
app.use('/sprint-61/', setVersionMiddleware('/sprint-61/'), require('./routes/sprint-61'));
app.use('/sprint-60-1/', setVersionMiddleware('/sprint-60-1/'), require('./routes/sprint-60-1'));
app.use('/sprint-60/', setVersionMiddleware('/sprint-60/'), require('./routes/sprint-60'));
app.use('/sprint-59/', setVersionMiddleware('/sprint-59/'), require('./routes/sprint-59'));
app.use('/sprint-58/', setVersionMiddleware('/sprint-58/'), require('./routes/sprint-58'));
app.use('/sprint-57/', setVersionMiddleware('/sprint-57/'), require('./routes/sprint-57'));
app.use('/sprint-56/', setVersionMiddleware('/sprint-56/'), require('./routes/sprint-56'));
app.use('/sprint-55/', setVersionMiddleware('/sprint-55/'), require('./routes/sprint-55'));
app.use('/sprint-54/', setVersionMiddleware('/sprint-54/'), require('./routes/sprint-54'));
app.use('/sprint-53/', setVersionMiddleware('/sprint-53/'), require('./routes/sprint-53'));
app.use('/sprint-48/', setVersionMiddleware('/sprint-48/'), require('./routes/sprint-48'));
app.use('/sprint-47/', setVersionMiddleware('/sprint-47/'), require('./routes/sprint-47'));
app.use('/v2-1-0/', setVersionMiddleware('/v2-1-0/'), require('./routes/v2-1-0'));
app.use('/v2-0-0/', setVersionMiddleware('/v2-0-0/'), require('./routes/v2-0-0'));
app.use('/v1-1-0/', setVersionMiddleware('/v1-1-0/'), require('./routes/v1-1-0'));
app.use('/', require('./routes/v1-0-0'));
app.get('/clear-data', (req, res) => {
req.session.destroy((err) => {
res.redirect('/') // will always fire after session is destroyed
});
});
// Request middleware - renders views for GET requests without controller
app.get(/^([^.]+)$/, (req, res, next) => {
const { path } = req;
if (path) {
handleGetRequest(path.substring(1))(req, res, next);
} else {
next();
}
});
// Actuator routes
app.use(actuatorRoutes(packageMeta));
// Error handling routes
app.use(notFoundRoutes);
app.listen(port, () => {
// eslint-disable-next-line
console.log(`App listening at http://localhost:${port}`);
});