11const express = require ( 'express' )
22const log4js = require ( 'log4js' )
3+ const compression = require ( 'compression' )
34const history = require ( 'connect-history-api-fallback' )
45const httpproxy = require ( './libs/proxy' )
56const http = require ( 'http' )
67const https = require ( 'https' )
78const qs = require ( 'querystring' )
89class Proxy {
910 constructor ( {
10- bind = { host : '0.0.0.0' , port : 3000 } , web = { dir : `${ __dirname } /public` } , proxy, redirect
11+ bind = { host : '0.0.0.0' , port : 3000 } , web = { dir : `${ __dirname } /public` } , proxy, redirect, compression = true
1112 } ) {
1213 this . bind = bind
1314 this . web = web
1415 this . proxy = proxy
1516 this . redirect = redirect
1617 this . app = express ( )
18+ this . compression = compression
1719 }
1820
1921 start ( ) {
@@ -23,6 +25,9 @@ class Proxy {
2325 } )
2426 const logger = log4js . getLogger ( )
2527 this . app . use ( log4js . connectLogger ( logger ) ) ;
28+ if ( this . compression ) {
29+ this . app . use ( compression ( ) )
30+ }
2631 if ( Array . isArray ( this . proxy ) ) {
2732 for ( let p of this . proxy ) {
2833 this . app . use ( p . path , httpproxy ( {
@@ -86,6 +91,7 @@ class Proxy {
8691 } )
8792 }
8893 }
94+
8995 this . app . use ( history ( ) )
9096 this . app . use ( express . static ( this . web . dir ) )
9197 this . app . listen ( this . bind . port , this . bind . host )
0 commit comments