33var express = require ( 'express' ) ,
44 favicon = require ( 'static-favicon' ) ,
55 morgan = require ( 'morgan' ) ,
6+ compression = require ( 'compression' ) ,
67 bodyParser = require ( 'body-parser' ) ,
78 methodOverride = require ( 'method-override' ) ,
89 cookieParser = require ( 'cookie-parser' ) ,
@@ -17,59 +18,60 @@ var express = require('express'),
1718 * Express configuration
1819 */
1920module . exports = function ( app ) {
20- var env = app . get ( 'env' ) ;
21+ var env = app . get ( 'env' ) ;
2122
22- if ( 'development' === env ) {
23- app . use ( require ( 'connect-livereload' ) ( ) ) ;
23+ if ( 'development' === env ) {
24+ app . use ( require ( 'connect-livereload' ) ( ) ) ;
2425
25- // Disable caching of scripts for easier testing
26- app . use ( function noCache ( req , res , next ) {
27- if ( req . url . indexOf ( '/scripts/' ) === 0 ) {
28- res . header ( 'Cache-Control' , 'no-cache, no-store, must-revalidate' ) ;
29- res . header ( 'Pragma' , 'no-cache' ) ;
30- res . header ( 'Expires' , 0 ) ;
31- }
32- next ( ) ;
33- } ) ;
26+ // Disable caching of scripts for easier testing
27+ app . use ( function noCache ( req , res , next ) {
28+ if ( req . url . indexOf ( '/scripts/' ) === 0 ) {
29+ res . header ( 'Cache-Control' , 'no-cache, no-store, must-revalidate' ) ;
30+ res . header ( 'Pragma' , 'no-cache' ) ;
31+ res . header ( 'Expires' , 0 ) ;
32+ }
33+ next ( ) ;
34+ } ) ;
3435
35- app . use ( express . static ( path . join ( config . root , '.tmp' ) ) ) ;
36- app . use ( express . static ( path . join ( config . root , 'app' ) ) ) ;
37- app . set ( 'views' , config . root + '/app/views' ) ;
38- }
36+ app . use ( express . static ( path . join ( config . root , '.tmp' ) ) ) ;
37+ app . use ( express . static ( path . join ( config . root , 'app' ) ) ) ;
38+ app . set ( 'views' , config . root + '/app/views' ) ;
39+ }
3940
40- if ( 'production' === env ) {
41- app . use ( favicon ( path . join ( config . root , 'public' , 'favicon.ico' ) ) ) ;
42- app . use ( express . static ( path . join ( config . root , 'public' ) ) ) ;
43- app . set ( 'views' , config . root + '/views' ) ;
44- }
41+ if ( 'production' === env ) {
42+ app . use ( compression ( ) ) ;
43+ app . use ( favicon ( path . join ( config . root , 'public' , 'favicon.ico' ) ) ) ;
44+ app . use ( express . static ( path . join ( config . root , 'public' ) ) ) ;
45+ app . set ( 'views' , config . root + '/views' ) ;
46+ }
4547
46- < % if ( ! jade ) { % >
47- app . engine ( 'html' , require ( 'ejs' ) . renderFile ) ;
48- app . set ( 'view engine' , 'html' ) ; < % } % > < % if ( jade ) { % >
49- app . set ( 'view engine' , 'jade' ) ; < % } % >
50- app . use ( morgan ( 'dev' ) ) ;
51- app . use ( bodyParser ( ) ) ;
52- app . use ( methodOverride ( ) ) ; < % if ( mongoPassportUser ) { % >
53- app . use ( cookieParser ( ) ) ;
48+ < % if ( ! jade ) { % >
49+ app . engine ( 'html' , require ( 'ejs' ) . renderFile ) ;
50+ app . set ( 'view engine' , 'html' ) ; < % } % > < % if ( jade ) { % >
51+ app . set ( 'view engine' , 'jade' ) ; < % } % >
52+ app . use ( morgan ( 'dev' ) ) ;
53+ app . use ( bodyParser ( ) ) ;
54+ app . use ( methodOverride ( ) ) ; < % if ( mongoPassportUser ) { % >
55+ app . use ( cookieParser ( ) ) ;
5456
55- // Persist sessions with mongoStore
56- app . use ( session ( {
57- secret : 'angular-fullstack secret' ,
58- store : new mongoStore ( {
59- url : config . mongo . uri ,
60- collection : 'sessions'
61- } , function ( ) {
62- console . log ( 'db connection open' ) ;
63- } )
64- } ) ) ;
57+ // Persist sessions with mongoStore
58+ app . use ( session ( {
59+ secret : 'angular-fullstack secret' ,
60+ store : new mongoStore ( {
61+ url : config . mongo . uri ,
62+ collection : 'sessions'
63+ } , function ( ) {
64+ console . log ( 'db connection open' ) ;
65+ } )
66+ } ) ) ;
6567
66- // Use passport session
67- app . use ( passport . initialize ( ) ) ;
68- app . use ( passport . session ( ) ) ;
69- < % } % >
68+ // Use passport session
69+ app . use ( passport . initialize ( ) ) ;
70+ app . use ( passport . session ( ) ) ;
71+ < % } % >
7072
71- // Error handler - has to be last
72- if ( 'development' === app . get ( 'env' ) ) {
73- app . use ( errorHandler ( ) )
74- }
73+ // Error handler - has to be last
74+ if ( 'development' === app . get ( 'env' ) ) {
75+ app . use ( errorHandler ( ) ) ;
76+ }
7577} ;
0 commit comments