@@ -5,25 +5,16 @@ import compression from 'compression';
5
5
import Api from './api' ;
6
6
import cookieParser from 'cookie-parser' ;
7
7
import ReactRenderer from './renderer' ;
8
+ import { httpsRedirect } from 'middleware' ;
8
9
9
10
const env = process . env . NODE_ENV || 'development' ;
10
- let app = new express ( ) ;
11
+ const app = new express ( ) ;
11
12
12
13
// Secure with helmet
13
14
app . use ( helmet ( ) ) ;
14
15
15
- /* Ensures SSL in used in production. To use, uncomment the below.
16
- app.use(function (req, res, next) {
17
- var sslUrl;
18
-
19
- if (env === 'production' && req.headers['x-forwarded-proto'] !== 'https') {
20
- sslUrl = [process.env.APPLICATION_BASE_URL, req.url].join('');
21
- return res.redirect(sslUrl);
22
- }
23
-
24
- return next();
25
- });
26
- */
16
+ // Ensures SSL in used in production.
17
+ app . use ( httpsRedirect ( { enabled : env === 'production' } ) ) ;
27
18
28
19
// parse cookies!
29
20
app . use ( cookieParser ( ) ) ;
@@ -32,14 +23,18 @@ app.use(cookieParser());
32
23
app . use ( compression ( ) ) ;
33
24
34
25
// Add middleware to serve up all static files
35
- app . use ( '/assets' ,
26
+ app . use (
27
+ '/assets' ,
36
28
express . static ( path . join ( __dirname , '../' + process . env . PUBLIC_OUTPUT_PATH ) ) ,
37
29
express . static ( path . join ( __dirname , '../common/images' ) ) ,
38
30
express . static ( path . join ( __dirname , '../common/fonts' ) )
39
31
) ;
40
32
41
33
// handle browsers requesting favicon
42
- app . use ( '/favicon.ico' , express . static ( path . join ( __dirname , '../common/images/favicon/favicon.ico' ) ) ) ;
34
+ app . use (
35
+ '/favicon.ico' ,
36
+ express . static ( path . join ( __dirname , '../common/images/favicon/favicon.ico' ) )
37
+ ) ;
43
38
44
39
// Mount the REST API
45
40
app . use ( '/api' , Api ) ;
0 commit comments