@@ -94,147 +94,158 @@ app.use('/assets/css', (req, res, next) => {
94
94
next ( ) ;
95
95
} , express . static ( path . join ( __dirname , './dist/assets/css' ) ) ) ;
96
96
97
- if ( config . SERVICE_UNAVAILABLE === true ) {
98
- app . all ( '*' , ( req , res ) => {
99
- console . log ( 'Service Unavailable.' ) ;
100
- res . status ( '503' ) ;
101
- res . sendFile ( path . join ( __dirname , '/app/static/service-unavailable.html' ) )
102
- } ) ;
103
- } else {
104
-
105
- // Production session data
106
- const session = require ( 'express-session' ) ;
107
- var redis = require ( "redis" ) ;
108
- var redisStore = connect_redis ( session ) ;
109
- var redisClient = redis . createClient ( {
110
- host : process . env . REDIS_HOST ,
111
- port : 6379 ,
112
- } ) ;
113
-
114
- const isSecure = env === 'production' && useHttps === 'true' ;
115
-
116
- if ( isSecure ) {
117
- app . use ( forceHttps ) ;
118
- }
119
-
120
- // Support for parsing data in POSTs
121
- app . use ( bodyParser . json ( ) ) ;
122
- app . use (
123
- bodyParser . urlencoded ( {
124
- extended : true ,
125
- } )
126
- ) ;
127
-
128
- app . set ( 'trust proxy' , 1 ) ; // needed for secure cookies on heroku
129
-
130
- // Configure nunjucks environment
131
- const nunjucksAppEnv = nunjucks . configure (
132
- [
133
- path . join ( __dirname , './node_modules/govuk-frontend/' ) ,
134
- path . join ( __dirname , './app/views/' ) ,
135
- ] ,
136
- {
137
- autoescape : false ,
138
- express : app ,
139
- watch : env === 'development' ? true : false ,
140
- }
141
- ) ;
142
- addCheckedFunction ( nunjucksAppEnv ) ;
143
- addNunjucksFilters ( nunjucksAppEnv ) ;
144
-
145
- // Set views engine
146
- app . set ( 'view engine' , 'html' ) ;
147
-
148
- app . use ( express . static ( path . join ( __dirname , './dist' ) ) ) ;
149
- app . use ( '/uploads' , express . static ( 'uploads' ) ) ;
150
- app . use ( '/auth' , express . static ( path . join ( __dirname , 'app' , 'static' , 'auth' ) ) ) ;
151
-
152
-
153
- app . use (
154
- '/assets' ,
155
- express . static (
156
- path . join ( __dirname , './node_modules/govuk-frontend/govuk/assets' )
157
- )
158
- ) ;
159
-
160
- // Serve CSS files specifically
161
- app . use ( '/assets/css' , ( req , res , next ) => {
162
- res . set ( 'Cache-Control' , 'no-cache, no-store, must-revalidate' ) ;
163
- next ( ) ;
164
- } , express . static ( path . join ( __dirname , './dist/assets/css' ) ) ) ;
165
-
166
-
167
- // Session uses service name to avoid clashes with other prototypes
168
- app . use ( session ( {
169
- secret : process . env . CSRFT_SESSION_SECRET ,
170
- store : new redisStore ( {
171
- client : redisClient ,
172
- ttl : 3600
173
- } ) ,
174
- sameSite : 'none' ,
175
- saveUninitialized : false ,
176
- resave : false ,
177
- cookie : { httpOnly : true , secure : isSecure } ,
178
- unset : 'destroy'
179
- } ) ) ;
180
-
181
- // Manage session data. Assigns default values to data
182
- app . use ( sessionData ) ;
183
-
184
- // Logs req.session data
185
- // if (env === 'development') edt(app, { panels: ['session'] });
186
-
187
-
188
-
189
- app . get ( '/' , function ( req , res ) {
190
- res . render ( 'index' ) ;
191
- } )
192
-
193
- // Load API routes
194
- app . use ( '/' , routes ( ) ) ;
195
-
196
- // Disables caching when user clicks back button on confirmation page
197
- app . use ( '/report/check-your-answers' , function ( req , res , next ) {
198
- res . set (
199
- 'Cache-Control' ,
200
- 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
201
- ) ;
202
- next ( ) ;
203
- } ) ;
204
-
205
- app . get ( / ^ ( [ ^ . ] + ) $ / , function ( req , res , next ) {
206
- if ( config . SERVICE_UNAVAILABLE === true ) {
207
- console . log ( 'Service Unavailable.' ) ;
208
- res . status ( '503' ) ;
209
- res . sendFile ( path . join ( __dirname , '/app/static/service-unavailable.html' ) ) ;
210
- } else {
211
- matchRoutes ( req , res , next ) ;
212
- }
213
- } ) ;
214
- // Redirect all POSTs to GETs
215
- app . post ( / ^ \/ ( [ ^ . ] + ) $ / , function ( req , res ) {
216
- res . redirect ( '/' + req . params [ 0 ] ) ;
217
- } ) ;
218
-
219
- // Catch 404 and forward to error handler
220
- app . use ( function ( req , res , next ) {
221
- var err = new Error ( `Page not found: ${ req . path } ` ) ;
222
- err . status = 404 ;
223
-
224
- next ( err ) ;
225
- } ) ;
226
-
227
- // Display error
228
- app . use ( function ( err , req , res , next ) {
229
- res . status ( err . status || 500 ) ;
230
-
231
- if ( err . message . indexOf ( 'not found' ) > 0 ) {
232
- res . status ( 404 ) . render ( '404' ) ;
233
- }
234
- } ) ;
235
- }
97
+ app . all ( '*' , ( req , res ) => {
98
+ console . log ( 'Service Unavailable.' ) ;
99
+ res . status ( '503' ) ;
100
+ res . sendFile ( path . join ( __dirname , '/app/static/service-unavailable.html' ) )
101
+ } ) ;
236
102
237
103
app . listen ( PORT , ( ) => {
238
104
console . log ( `App listening on ${ PORT } - url: http://localhost:${ PORT } ` ) ;
239
105
console . log ( 'Press Ctrl+C to quit.' ) ;
240
106
} ) ;
107
+
108
+ // if (config.SERVICE_UNAVAILABLE === true) {
109
+ // app.all('*', (req, res) => {
110
+ // console.log('Service Unavailable.');
111
+ // res.status('503');
112
+ // res.sendFile(path.join(__dirname, '/app/static/service-unavailable.html'))
113
+ // });
114
+ // } else {
115
+ //
116
+ // // Production session data
117
+ // const session = require('express-session');
118
+ // var redis = require("redis");
119
+ // var redisStore = connect_redis(session);
120
+ // var redisClient = redis.createClient({
121
+ // host: process.env.REDIS_HOST,
122
+ // port: 6379,
123
+ // });
124
+ //
125
+ // const isSecure = env === 'production' && useHttps === 'true';
126
+ //
127
+ // if (isSecure) {
128
+ // app.use(forceHttps);
129
+ // }
130
+ //
131
+ // // Support for parsing data in POSTs
132
+ // app.use(bodyParser.json());
133
+ // app.use(
134
+ // bodyParser.urlencoded({
135
+ // extended: true,
136
+ // })
137
+ // );
138
+ //
139
+ // app.set('trust proxy', 1); // needed for secure cookies on heroku
140
+ //
141
+ // // Configure nunjucks environment
142
+ // const nunjucksAppEnv = nunjucks.configure(
143
+ // [
144
+ // path.join(__dirname, './node_modules/govuk-frontend/'),
145
+ // path.join(__dirname, './app/views/'),
146
+ // ],
147
+ // {
148
+ // autoescape: false,
149
+ // express: app,
150
+ // watch: env === 'development' ? true : false,
151
+ // }
152
+ // );
153
+ // addCheckedFunction(nunjucksAppEnv);
154
+ // addNunjucksFilters(nunjucksAppEnv);
155
+ //
156
+ // // Set views engine
157
+ // app.set('view engine', 'html');
158
+ //
159
+ // app.use(express.static(path.join(__dirname, './dist')));
160
+ // app.use('/uploads', express.static('uploads'));
161
+ // app.use('/auth', express.static(path.join(__dirname, 'app', 'static', 'auth')));
162
+ //
163
+ //
164
+ // app.use(
165
+ // '/assets',
166
+ // express.static(
167
+ // path.join(__dirname, './node_modules/govuk-frontend/govuk/assets')
168
+ // )
169
+ // );
170
+ //
171
+ // // Serve CSS files specifically
172
+ // app.use('/assets/css', (req, res, next) => {
173
+ // res.set('Cache-Control', 'no-cache, no-store, must-revalidate');
174
+ // next();
175
+ // }, express.static(path.join(__dirname, './dist/assets/css')));
176
+ //
177
+ //
178
+ // // Session uses service name to avoid clashes with other prototypes
179
+ // app.use(session({
180
+ // secret: process.env.CSRFT_SESSION_SECRET,
181
+ // store: new redisStore({
182
+ // client: redisClient,
183
+ // ttl: 3600
184
+ // }),
185
+ // sameSite: 'none',
186
+ // saveUninitialized: false,
187
+ // resave: false,
188
+ // cookie: { httpOnly: true , secure: isSecure},
189
+ // unset: 'destroy'
190
+ // }));
191
+ //
192
+ // // Manage session data. Assigns default values to data
193
+ // app.use(sessionData);
194
+ //
195
+ // // Logs req.session data
196
+ // // if (env === 'development') edt(app, { panels: ['session'] });
197
+ //
198
+ //
199
+ //
200
+ // app.get('/', function(req, res){
201
+ // res.render('index');
202
+ // })
203
+ //
204
+ // // Load API routes
205
+ // app.use('/', routes());
206
+ //
207
+ // // Disables caching when user clicks back button on confirmation page
208
+ // app.use('/report/check-your-answers', function (req, res, next) {
209
+ // res.set(
210
+ // 'Cache-Control',
211
+ // 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
212
+ // );
213
+ // next();
214
+ // });
215
+ //
216
+ // app.get(/^([^.]+)$/, function (req, res, next) {
217
+ // if (config.SERVICE_UNAVAILABLE === true) {
218
+ // console.log('Service Unavailable.');
219
+ // res.status('503');
220
+ // res.sendFile(path.join(__dirname, '/app/static/service-unavailable.html'));
221
+ // } else {
222
+ // matchRoutes(req, res, next);
223
+ // }
224
+ // });
225
+ // // Redirect all POSTs to GETs
226
+ // app.post(/^\/([^.]+)$/, function (req, res) {
227
+ // res.redirect('/' + req.params[0]);
228
+ // });
229
+ //
230
+ // // Catch 404 and forward to error handler
231
+ // app.use(function (req, res, next) {
232
+ // var err = new Error(`Page not found: ${req.path}`);
233
+ // err.status = 404;
234
+ //
235
+ // next(err);
236
+ // });
237
+ //
238
+ // // Display error
239
+ // app.use(function (err, req, res, next) {
240
+ // res.status(err.status || 500);
241
+ //
242
+ // if (err.message.indexOf('not found') > 0) {
243
+ // res.status(404).render('404');
244
+ // }
245
+ // });
246
+ // }
247
+ //
248
+ // app.listen(PORT, () => {
249
+ // console.log(`App listening on ${PORT} - url: http://localhost:${PORT}`);
250
+ // console.log('Press Ctrl+C to quit.');
251
+ // });
0 commit comments