@@ -3,6 +3,7 @@ const files = require('serve-static')
33const path = require ( 'path' )
44const cache = require ( 'http-cache-middleware' )
55const morgan = require ( 'morgan' )
6+ const middlewares = require ( './middlewares' )
67
78module . exports = ( ) => {
89 // configuration
@@ -19,7 +20,7 @@ module.exports = () => {
1920 'dist/'
2021 const port = PORT || config . get ( 'port' ) ||
2122 3000
22- const cacheEnabled = isCacheEnabled ( CACHE_ENABLED , config )
23+ const cacheEnabled = isEnabled ( CACHE_ENABLED , 'cacheEnabled' , config )
2324 const cacheControlHeaderValue = CACHE_CONTROL_HEADER_VALUE || config . get ( 'cacheControlHeaderValue' ) ||
2425 'public, no-cache, max-age=604800'
2526 const defaultFile = DEFALUT_FILE || config . get ( 'defaultFile' ) ||
@@ -47,6 +48,13 @@ module.exports = () => {
4748
4849 return next ( )
4950 } )
51+
52+ // supporting custom middlewares
53+ for ( const middleware of middlewares ) {
54+ server . use ( middleware ( ) )
55+ }
56+
57+ // supporting cache
5058 if ( cacheEnabled ) {
5159 server . use ( cache ( ) )
5260 }
@@ -58,11 +66,11 @@ module.exports = () => {
5866 }
5967}
6068
61- function isCacheEnabled ( env , config ) {
69+ function isEnabled ( env , configKey , config ) {
6270 if ( env !== undefined ) {
6371 if ( env === 'true' ) return true
6472 else return false
6573 } else {
66- return config . get ( 'cacheEnabled' ) || true
74+ return config . get ( configKey ) || true
6775 }
6876}
0 commit comments