@@ -13,18 +13,23 @@ class ExpressHTTPServer {
1313 this . password = options . password ;
1414 this . cache = options . cache ;
1515 this . gzip = options . gzip || false ;
16+ this . preFastbootMiddlewares = options . preFastbootMiddlewares || [ ] ;
17+ this . postFastbootMiddlewares = options . postFastbootMiddlewares || [ ] ;
1618
1719 this . app = express ( ) ;
18- if ( options . gzip ) {
19- this . app . use ( require ( 'compression' ) ( ) ) ;
20- }
2120 }
2221
23- serve ( middleware ) {
22+ serve ( fastbootMiddleware ) {
2423 let app = this . app ;
2524 let username = this . username ;
2625 let password = this . password ;
2726
27+ this . preFastbootMiddlewares . forEach ( args => app . use ( ...args ) ) ;
28+
29+ if ( this . gzip ) {
30+ this . app . use ( require ( 'compression' ) ( ) ) ;
31+ }
32+
2833 if ( username !== undefined || password !== undefined ) {
2934 this . ui . writeLine ( `adding basic auth; username=${ username } ; password=${ password } ` ) ;
3035 app . use ( basicAuth ( username , password ) ) ;
@@ -35,11 +40,13 @@ class ExpressHTTPServer {
3540 }
3641
3742 if ( this . distPath ) {
38- app . get ( '/' , middleware ) ;
43+ app . get ( '/' , fastbootMiddleware ) ;
3944 app . use ( express . static ( this . distPath ) ) ;
4045 }
4146
42- app . get ( '/*' , middleware ) ;
47+ app . get ( '/*' , fastbootMiddleware ) ;
48+
49+ this . postFastbootMiddlewares . forEach ( args => app . use ( ...args ) ) ;
4350
4451 return new Promise ( resolve => {
4552 let listener = app . listen ( process . env . PORT || 3000 , ( ) => {
0 commit comments