@@ -115,20 +115,32 @@ var utils = {
115115 getBaseApp : function ( bs , scripts ) {
116116
117117 var app = connect ( ) ;
118- var rule = require ( "./proxy-utils" ) . rewriteLinks ( bs . options . getIn ( [ "proxy" , "url" ] ) . toJS ( ) ) ;
119-
120- bs . snippetMw . opts . rules . push ( rule ) ;
121-
122- /**
123- * Add the snippet middleware to the front of the stack
124- */
125- app . use ( bs . snippetMw . middleware ) ;
126118
127119 /**
128- * Serve the Client-side JS from both version and static paths
120+ * Add the proxy Middleware to the end of the stack
129121 */
130- app . use ( bs . options . getIn ( [ "scriptPaths" , "versioned" ] ) , scripts )
131- . use ( bs . options . getIn ( [ "scriptPaths" , "path" ] ) , scripts ) ;
122+ app . stack . push (
123+ {
124+ id : "Browsersync IE8 Support" ,
125+ route : "" ,
126+ handle : utils . handleOldIE
127+ } ,
128+ {
129+ id : "Browsersync Response Modifier" ,
130+ route : "" ,
131+ handle : utils . getSnippetMiddleware ( bs )
132+ } ,
133+ {
134+ id : "Browsersync Client - versioned" ,
135+ route : bs . options . getIn ( [ "scriptPaths" , "versioned" ] ) ,
136+ handle : scripts
137+ } ,
138+ {
139+ id : "Browsersync Client" ,
140+ route : bs . options . getIn ( [ "scriptPaths" , "path" ] ) ,
141+ handle : scripts
142+ }
143+ ) ;
132144
133145 /**
134146 * Add user-provided middlewares
@@ -138,6 +150,13 @@ var utils = {
138150 } ) ;
139151
140152 return app ;
153+ } ,
154+ getSnippetMiddleware : function ( bs ) {
155+ if ( bs . options . get ( "proxy" ) ) {
156+ var rule = require ( "./proxy-utils" ) . rewriteLinks ( bs . options . getIn ( [ "proxy" , "url" ] ) . toJS ( ) ) ;
157+ bs . snippetMw . opts . rules . push ( rule ) ;
158+ }
159+ return bs . snippetMw . middleware ;
141160 }
142161} ;
143162
0 commit comments