@@ -11,6 +11,8 @@ module.exports = function (env, callback) {
1111 lessMiddleWare = require ( "less-middleware" ) ,
1212 WebmakerAuth = require ( "webmaker-auth" ) ,
1313 nunjucks = require ( "nunjucks" ) ,
14+ morgan = require ( "morgan" ) ,
15+ errorHandler = require ( "errorhandler" ) ,
1416 path = require ( "path" ) ,
1517 route = require ( "./routes" ) ,
1618 http = express ( ) ;
@@ -52,80 +54,73 @@ module.exports = function (env, callback) {
5254 } ) ;
5355
5456 // Express Configuration
55- http . configure ( function ( ) {
56- nunjucksEnv . express ( http ) ;
57+ nunjucksEnv . express ( http ) ;
5758
58- http . disable ( "x-powered-by" ) ;
59+ http . disable ( "x-powered-by" ) ;
5960
60- if ( ! env . get ( "DISABLE_HTTP_LOGGING" ) ) {
61- http . use ( express . logger ( ) ) ;
62- }
61+ if ( ! env . get ( "DISABLE_HTTP_LOGGING" ) ) {
62+ http . use ( morgan ( "combined" ) ) ;
63+ }
6364
64- http . use ( helmet . iexss ( ) ) ;
65- http . use ( helmet . contentTypeOptions ( ) ) ;
66- http . use ( helmet . xframe ( ) ) ;
65+ http . use ( helmet . iexss ( ) ) ;
66+ http . use ( helmet . contentTypeOptions ( ) ) ;
67+ http . use ( helmet . xframe ( ) ) ;
6768
68- if ( ! ! env . get ( "FORCE_SSL" ) ) {
69- http . use ( helmet . hsts ( ) ) ;
70- http . enable ( "trust proxy" ) ;
69+ if ( ! ! env . get ( "FORCE_SSL" ) ) {
70+ http . use ( helmet . hsts ( ) ) ;
71+ http . enable ( "trust proxy" ) ;
72+ }
73+
74+ http . use ( express . json ( ) ) ;
75+ http . use ( express . urlencoded ( { extended : false } ) ) ;
76+ http . use ( webmakerAuth . cookieParser ( ) ) ;
77+ http . use ( webmakerAuth . cookieSession ( ) ) ;
78+
79+ // Setup locales with i18n
80+ http . use ( i18n . middleware ( {
81+ supported_languages : env . get ( "SUPPORTED_LANGS" ) ,
82+ default_lang : "en-US" ,
83+ mappings : require ( "webmaker-locale-mapping" ) ,
84+ translation_directory : path . resolve ( __dirname , "../../locale" )
85+ } ) ) ;
86+
87+ // audience and webmakerorg are duplicated because of i18n
88+ http . locals . AUDIENCE = env . get ( "WEBMAKERORG" ) ;
89+ http . locals . WEBMAKERORG = env . get ( "WEBMAKERORG" ) ;
90+ http . locals . profile = env . get ( "PROFILE" ) ;
91+ http . locals . bower_path = "bower_components" ;
92+ http . locals . personaHostname = env . get ( "PERSONA_HOSTNAME" , "https://login.persona.org" ) ;
93+ http . locals . languages = i18n . getSupportLanguages ( ) ;
94+
95+ var optimize = env . get ( "NODE_ENV" ) !== "development" ,
96+ tmpDir = path . join ( require ( "os" ) . tmpdir ( ) , "mozilla.login.webmaker.org.build" ) ;
97+
98+ // convert requests for ltr- or rtl-specific CSS back to the real filename,
99+ // as the rtltr-for-less package was a hack that was never meant to hit production.
100+ http . use ( function rtltrRedirect ( req , res , next ) {
101+ var path = req . path ;
102+ if ( path . match ( / c s s \/ \w + \. ( l t r | r t l ) \. c s s / ) ) {
103+ res . redirect ( path . replace ( / \. ( l t r | r t l ) / , "" ) ) ;
104+ } else {
105+ next ( ) ;
71106 }
107+ } ) ;
72108
73- http . use ( express . json ( ) ) ;
74- http . use ( express . urlencoded ( ) ) ;
75- http . use ( webmakerAuth . cookieParser ( ) ) ;
76- http . use ( webmakerAuth . cookieSession ( ) ) ;
77-
78- // Setup locales with i18n
79- http . use ( i18n . middleware ( {
80- supported_languages : env . get ( "SUPPORTED_LANGS" ) ,
81- default_lang : "en-US" ,
82- mappings : require ( "webmaker-locale-mapping" ) ,
83- translation_directory : path . resolve ( __dirname , "../../locale" )
84- } ) ) ;
85-
86- http . locals ( {
87- // audience and webmakerorg are duplicated because of i18n
88- AUDIENCE : env . get ( "WEBMAKERORG" ) ,
89- WEBMAKERORG : env . get ( "WEBMAKERORG" ) ,
90- profile : env . get ( "PROFILE" ) ,
91- bower_path : "bower_components" ,
92- personaHostname : env . get ( "PERSONA_HOSTNAME" , "https://login.persona.org" ) ,
93- languages : i18n . getSupportLanguages ( )
94- } ) ;
109+ http . use ( lessMiddleWare ( path . resolve ( __dirname , "public" ) , {
110+ once : optimize ,
111+ debug : ! optimize ,
112+ dest : tmpDir ,
113+ compress : optimize ,
114+ yuicompress : optimize ,
115+ optimization : optimize ? 0 : 2
116+ } ) ) ;
95117
96- // need to make sure router is after i18n.middleware
97- http . use ( http . router ) ;
98-
99- var optimize = env . get ( "NODE_ENV" ) !== "development" ,
100- tmpDir = path . join ( require ( "os" ) . tmpdir ( ) , "mozilla.login.webmaker.org.build" ) ;
101-
102- // convert requests for ltr- or rtl-specific CSS back to the real filename,
103- // as the rtltr-for-less package was a hack that was never meant to hit production.
104- http . use ( function rtltrRedirect ( req , res , next ) {
105- var path = req . path ;
106- if ( path . match ( / c s s \/ \w + \. ( l t r | r t l ) \. c s s / ) ) {
107- res . redirect ( path . replace ( / \. ( l t r | r t l ) / , "" ) ) ;
108- } else {
109- next ( ) ;
110- }
111- } ) ;
118+ http . use ( express . static ( tmpDir ) ) ;
112119
113- http . use ( lessMiddleWare ( {
114- once : optimize ,
115- debug : ! optimize ,
116- dest : tmpDir ,
117- src : path . resolve ( __dirname , "public" ) ,
118- compress : optimize ,
119- yuicompress : optimize ,
120- optimization : optimize ? 0 : 2
121- } ) ) ;
122-
123- http . use ( express . static ( tmpDir ) ) ;
124- } ) ;
125120
126- http . configure ( "development" , function ( ) {
127- http . use ( express . errorHandler ( ) ) ;
128- } ) ;
121+ if ( env . get ( "NODE_ENV" ) === "development" ) {
122+ http . use ( errorHandler ( ) ) ;
123+ }
129124
130125 route ( http , Models , webmakerAuth ) ;
131126
0 commit comments