@@ -20,8 +20,10 @@ const RATE_WINDOW = 15 * 60 * 1000;
2020const bind = ( f , self ) => f . bind ( self ) ;
2121
2222const two = currify ( ( f , a , b ) => f ( a , b ) ) ;
23- const shutdown = wraptile ( async ( promises ) => {
24- console . log ( 'closing cloudcmd...' ) ;
23+ const shutdown = wraptile ( async ( config , promises ) => {
24+ if ( config ( 'log' ) )
25+ console . log ( 'closing cloudcmd...' ) ;
26+
2527 await Promise . all ( promises ) ;
2628 process . exit ( 0 ) ;
2729} ) ;
@@ -41,7 +43,7 @@ export default async (options, config) => {
4143 const app = express ( ) ;
4244 const server = http . createServer ( app ) ;
4345
44- if ( logger )
46+ if ( config ( 'log' ) && logger )
4547 app . use ( logger ( 'dev' ) ) ;
4648
4749 if ( prefix )
@@ -56,6 +58,8 @@ export default async (options, config) => {
5658 limit : RATE_LIMIT ,
5759 } ) ;
5860
61+ app . set ( 'trust proxy' , 1 ) ;
62+
5963 app . use ( compression ( ) ) ;
6064 app . use ( limiter ) ;
6165 app . use ( prefix , cloudcmd ( {
@@ -74,16 +78,17 @@ export default async (options, config) => {
7478 server . on ( 'error' , exitPort ) ;
7579 await listen ( port , ip ) ;
7680
77- const close = shutdown ( [ closeServer , closeSocket ] ) ;
81+ const close = shutdown ( config , [ closeServer , closeSocket ] ) ;
7882
7983 process . on ( 'SIGINT' , close ) ;
80- process . on ( 'SIUSR1 ' , close ) ;
84+ process . on ( 'SIGUSR1 ' , close ) ;
8185
8286 const host = config ( 'ip' ) || 'localhost' ;
8387 const port0 = port || server . address ( ) . port ;
8488 const url = `http://${ host } :${ port0 } ${ prefix } /` ;
8589
86- console . log ( `url: ${ url } ` ) ;
90+ if ( config ( 'log' ) )
91+ console . log ( `url: ${ url } ` ) ;
8792
8893 if ( ! config ( 'open' ) )
8994 return ;
0 commit comments