@@ -31,6 +31,19 @@ routesApi.setApp(app)
31
31
// Set up configuration variables
32
32
const releaseVersion = packageJson . version
33
33
34
+ // Find GOV.UK Frontend (via project, internal package fallback)
35
+ const govukFrontend = govukFrontendPaths ( [ projectDir , packageDir ] )
36
+
37
+ // Find GOV.UK Frontend (via internal package, project fallback)
38
+ const govukFrontendInternal = govukFrontendPaths ( [ packageDir , projectDir ] )
39
+
40
+ // Finds GOV.UK Frontend via `getAppViews()` only if installed
41
+ // but uses the internal package as a backup if uninstalled
42
+ const nunjucksAppEnv = getNunjucksAppEnv (
43
+ plugins . getAppViews ( [ appViewsDir , finalBackupNunjucksDir ] ) ,
44
+ govukFrontendInternal
45
+ )
46
+
34
47
// Force HTTPS on production. Do this before using basicAuth to avoid
35
48
// asking for username/password twice (for `http`, then `https`).
36
49
const isSecure = ( config . isProduction && config . useHttps )
@@ -39,12 +52,6 @@ if (isSecure) {
39
52
app . set ( 'trust proxy' , 1 ) // needed for secure cookies on heroku
40
53
}
41
54
42
- // Find GOV.UK Frontend (via project, internal package fallback)
43
- const govukFrontend = govukFrontendPaths ( [ projectDir , packageDir ] )
44
-
45
- // Find GOV.UK Frontend (via internal package, project fallback)
46
- const govukFrontendInternal = govukFrontendPaths ( [ packageDir , projectDir ] )
47
-
48
55
// Add variables that are available in all views
49
56
app . locals . asset_path = '/public/'
50
57
app . locals . useAutoStoreData = config . useAutoStoreData
@@ -90,23 +97,6 @@ if (config.isDevelopment) {
90
97
nunjucksConfig . watch = true
91
98
}
92
99
93
- nunjucksConfig . express = app
94
-
95
- // Finds GOV.UK Frontend via `getAppViews()` only if installed
96
- // but uses the internal package as a backup if uninstalled
97
- const nunjucksAppEnv = getNunjucksAppEnv (
98
- plugins . getAppViews ( [ appViewsDir , finalBackupNunjucksDir ] ) ,
99
- govukFrontendInternal
100
- )
101
-
102
- expressNunjucks ( nunjucksAppEnv , app )
103
-
104
- // Add Nunjucks filters
105
- utils . addNunjucksFilters ( nunjucksAppEnv )
106
-
107
- // Add Nunjucks functions
108
- utils . addNunjucksFunctions ( nunjucksAppEnv )
109
-
110
100
// Set views engine
111
101
app . set ( 'view engine' , 'njk' )
112
102
@@ -120,19 +110,19 @@ app.use(bodyParser.urlencoded({
120
110
extended : true
121
111
} ) )
122
112
123
- // Automatically store all data users enter
124
- if ( config . useAutoStoreData ) {
125
- app . use ( sessionUtils . autoStoreData )
126
- sessionUtils . addCheckedFunction ( nunjucksAppEnv )
127
- }
128
-
129
113
// Prevent search indexing
130
114
app . use ( ( req , res , next ) => {
131
115
// Setting headers stops pages being indexed even if indexed pages link to them.
132
116
res . setHeader ( 'X-Robots-Tag' , 'noindex' )
133
117
next ( )
134
118
} )
135
119
120
+ // Automatically store all data users enter
121
+ if ( config . useAutoStoreData ) {
122
+ app . use ( sessionUtils . autoStoreData )
123
+ sessionUtils . addCheckedFunction ( nunjucksAppEnv )
124
+ }
125
+
136
126
require ( './lib/manage-prototype-routes.js' )
137
127
require ( './lib/plugins/plugins-routes.js' )
138
128
const { getErrorModel } = require ( './lib/utils/errorModel' )
@@ -217,4 +207,14 @@ app.use((err, req, res, next) => {
217
207
218
208
app . close = stopWatchingNunjucks
219
209
210
+ nunjucksConfig . express = app
211
+
212
+ expressNunjucks ( nunjucksAppEnv , app )
213
+
214
+ // Add Nunjucks filters
215
+ utils . addNunjucksFilters ( nunjucksAppEnv )
216
+
217
+ // Add Nunjucks functions
218
+ utils . addNunjucksFunctions ( nunjucksAppEnv )
219
+
220
220
module . exports = app
0 commit comments