2
2
3
3
'use strict' ;
4
4
5
- var colors = require ( 'colors/safe ' ) ,
5
+ var chalk = require ( 'chalk ' ) ,
6
6
os = require ( 'os' ) ,
7
7
httpServer = require ( '../lib/http-server' ) ,
8
8
portfinder = require ( 'portfinder' ) ,
@@ -99,21 +99,21 @@ if (!argv.s && !argv.silent) {
99
99
if ( error ) {
100
100
logger . info (
101
101
'[%s] %s "%s %s" Error (%s): "%s"' ,
102
- date , ip , colors . red ( req . method ) , colors . red ( req . url ) ,
103
- colors . red ( error . status . toString ( ) ) , colors . red ( error . message )
102
+ date , ip , chalk . red ( req . method ) , chalk . red ( req . url ) ,
103
+ chalk . red ( error . status . toString ( ) ) , chalk . red ( error . message )
104
104
) ;
105
105
}
106
106
else {
107
107
logger . info (
108
108
'[%s] %s "%s %s" "%s"' ,
109
- date , ip , colors . cyan ( req . method ) , colors . cyan ( req . url ) ,
109
+ date , ip , chalk . cyan ( req . method ) , chalk . cyan ( req . url ) ,
110
110
req . headers [ 'user-agent' ]
111
111
) ;
112
112
}
113
113
}
114
114
} ;
115
115
}
116
- else if ( colors ) {
116
+ else if ( chalk ) {
117
117
logger = {
118
118
info : function ( ) { } ,
119
119
request : function ( ) { }
@@ -168,7 +168,7 @@ function listen(port) {
168
168
new url . URL ( proxy )
169
169
}
170
170
catch ( err ) {
171
- logger . info ( colors . red ( 'Error: Invalid proxy url' ) ) ;
171
+ logger . info ( chalk . red ( 'Error: Invalid proxy url' ) ) ;
172
172
process . exit ( 1 ) ;
173
173
}
174
174
}
@@ -183,14 +183,14 @@ function listen(port) {
183
183
fs . lstatSync ( options . https . cert ) ;
184
184
}
185
185
catch ( err ) {
186
- logger . info ( colors . red ( 'Error: Could not find certificate ' + options . https . cert ) ) ;
186
+ logger . info ( chalk . red ( 'Error: Could not find certificate ' + options . https . cert ) ) ;
187
187
process . exit ( 1 ) ;
188
188
}
189
189
try {
190
190
fs . lstatSync ( options . https . key ) ;
191
191
}
192
192
catch ( err ) {
193
- logger . info ( colors . red ( 'Error: Could not find private key ' + options . https . key ) ) ;
193
+ logger . info ( chalk . red ( 'Error: Could not find private key ' + options . https . key ) ) ;
194
194
process . exit ( 1 ) ;
195
195
}
196
196
}
@@ -200,34 +200,34 @@ function listen(port) {
200
200
var protocol = tls ? 'https://' : 'http://' ;
201
201
202
202
logger . info ( [
203
- colors . yellow ( 'Starting up http-server, serving ' ) ,
204
- colors . cyan ( server . root ) ,
205
- tls ? ( colors . yellow ( ' through' ) + colors . cyan ( ' https' ) ) : ''
203
+ chalk . yellow ( 'Starting up http-server, serving ' ) ,
204
+ chalk . cyan ( server . root ) ,
205
+ tls ? ( chalk . yellow ( ' through' ) + chalk . cyan ( ' https' ) ) : ''
206
206
] . join ( '' ) ) ;
207
207
208
- logger . info ( [ colors . yellow ( '\nhttp-server version: ' ) , colors . cyan ( require ( '../package.json' ) . version ) ] . join ( '' ) ) ;
208
+ logger . info ( [ chalk . yellow ( '\nhttp-server version: ' ) , chalk . cyan ( require ( '../package.json' ) . version ) ] . join ( '' ) ) ;
209
209
210
210
logger . info ( [
211
- colors . yellow ( '\nhttp-server settings: ' ) ,
212
- ( [ colors . yellow ( 'CORS: ' ) , argv . cors ? colors . cyan ( argv . cors ) : colors . red ( 'disabled' ) ] . join ( '' ) ) ,
213
- ( [ colors . yellow ( 'Cache: ' ) , argv . c ? ( argv . c === '-1' ? colors . red ( 'disabled' ) : colors . cyan ( argv . c + ' seconds' ) ) : colors . cyan ( '3600 seconds' ) ] . join ( '' ) ) ,
214
- ( [ colors . yellow ( 'Connection Timeout: ' ) , argv . t === '0' ? colors . red ( 'disabled' ) : ( argv . t ? colors . cyan ( argv . t + ' seconds' ) : colors . cyan ( '120 seconds' ) ) ] . join ( '' ) ) ,
215
- ( [ colors . yellow ( 'Directory Listings: ' ) , argv . d ? colors . red ( 'not visible' ) : colors . cyan ( 'visible' ) ] . join ( '' ) ) ,
216
- ( [ colors . yellow ( 'AutoIndex: ' ) , argv . i ? colors . red ( 'not visible' ) : colors . cyan ( 'visible' ) ] . join ( '' ) ) ,
217
- ( [ colors . yellow ( 'Serve GZIP Files: ' ) , argv . g || argv . gzip ? colors . cyan ( 'true' ) : colors . red ( 'false' ) ] . join ( '' ) ) ,
218
- ( [ colors . yellow ( 'Serve Brotli Files: ' ) , argv . b || argv . brotli ? colors . cyan ( 'true' ) : colors . red ( 'false' ) ] . join ( '' ) ) ,
219
- ( [ colors . yellow ( 'Default File Extension: ' ) , argv . e ? colors . cyan ( argv . e ) : ( argv . ext ? colors . cyan ( argv . ext ) : colors . red ( 'none' ) ) ] . join ( '' ) )
211
+ chalk . yellow ( '\nhttp-server settings: ' ) ,
212
+ ( [ chalk . yellow ( 'CORS: ' ) , argv . cors ? chalk . cyan ( argv . cors ) : chalk . red ( 'disabled' ) ] . join ( '' ) ) ,
213
+ ( [ chalk . yellow ( 'Cache: ' ) , argv . c ? ( argv . c === '-1' ? chalk . red ( 'disabled' ) : chalk . cyan ( argv . c + ' seconds' ) ) : chalk . cyan ( '3600 seconds' ) ] . join ( '' ) ) ,
214
+ ( [ chalk . yellow ( 'Connection Timeout: ' ) , argv . t === '0' ? chalk . red ( 'disabled' ) : ( argv . t ? chalk . cyan ( argv . t + ' seconds' ) : chalk . cyan ( '120 seconds' ) ) ] . join ( '' ) ) ,
215
+ ( [ chalk . yellow ( 'Directory Listings: ' ) , argv . d ? chalk . red ( 'not visible' ) : chalk . cyan ( 'visible' ) ] . join ( '' ) ) ,
216
+ ( [ chalk . yellow ( 'AutoIndex: ' ) , argv . i ? chalk . red ( 'not visible' ) : chalk . cyan ( 'visible' ) ] . join ( '' ) ) ,
217
+ ( [ chalk . yellow ( 'Serve GZIP Files: ' ) , argv . g || argv . gzip ? chalk . cyan ( 'true' ) : chalk . red ( 'false' ) ] . join ( '' ) ) ,
218
+ ( [ chalk . yellow ( 'Serve Brotli Files: ' ) , argv . b || argv . brotli ? chalk . cyan ( 'true' ) : chalk . red ( 'false' ) ] . join ( '' ) ) ,
219
+ ( [ chalk . yellow ( 'Default File Extension: ' ) , argv . e ? chalk . cyan ( argv . e ) : ( argv . ext ? chalk . cyan ( argv . ext ) : chalk . red ( 'none' ) ) ] . join ( '' ) )
220
220
] . join ( '\n' ) ) ;
221
221
222
- logger . info ( colors . yellow ( '\nAvailable on:' ) ) ;
222
+ logger . info ( chalk . yellow ( '\nAvailable on:' ) ) ;
223
223
224
224
if ( argv . a && host !== '0.0.0.0' ) {
225
- logger . info ( ` ${ protocol } ${ host } :${ colors . green ( port . toString ( ) ) } ` ) ;
225
+ logger . info ( ` ${ protocol } ${ host } :${ chalk . green ( port . toString ( ) ) } ` ) ;
226
226
} else {
227
227
Object . keys ( ifaces ) . forEach ( function ( dev ) {
228
228
ifaces [ dev ] . forEach ( function ( details ) {
229
229
if ( details . family === 'IPv4' ) {
230
- logger . info ( ( ' ' + protocol + details . address + ':' + colors . green ( port . toString ( ) ) ) ) ;
230
+ logger . info ( ( ' ' + protocol + details . address + ':' + chalk . green ( port . toString ( ) ) ) ) ;
231
231
}
232
232
} ) ;
233
233
} ) ;
@@ -268,11 +268,11 @@ if (process.platform === 'win32') {
268
268
}
269
269
270
270
process . on ( 'SIGINT' , function ( ) {
271
- logger . info ( colors . red ( 'http-server stopped.' ) ) ;
271
+ logger . info ( chalk . red ( 'http-server stopped.' ) ) ;
272
272
process . exit ( ) ;
273
273
} ) ;
274
274
275
275
process . on ( 'SIGTERM' , function ( ) {
276
- logger . info ( colors . red ( 'http-server stopped.' ) ) ;
276
+ logger . info ( chalk . red ( 'http-server stopped.' ) ) ;
277
277
process . exit ( ) ;
278
278
} ) ;
0 commit comments