@@ -7,9 +7,14 @@ var colors = require('colors/safe'),
77 httpServer = require ( '../lib/http-server' ) ,
88 portfinder = require ( 'portfinder' ) ,
99 opener = require ( 'opener' ) ,
10+
1011 fs = require ( 'fs' ) ,
11- argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ,
1212 url = require ( 'url' ) ;
13+ var argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) , {
14+ alias : {
15+ tls : 'ssl'
16+ }
17+ } ) ;
1318var ifaces = os . networkInterfaces ( ) ;
1419
1520process . title = 'http-server' ;
@@ -39,16 +44,17 @@ if (argv.h || argv.help) {
3944 ' -U --utc Use UTC time format in log messages.' ,
4045 ' --log-ip Enable logging of the client\'s IP address' ,
4146 '' ,
42- ' -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com' ,
47+ ' -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com' ,
48+ ' --proxy-options Pass options to proxy using nested dotted objects. e.g.: --proxy-options.secure false' ,
4349 '' ,
4450 ' --username Username for basic authentication [none]' ,
4551 ' Can also be specified with the env variable NODE_HTTP_SERVER_USERNAME' ,
4652 ' --password Password for basic authentication [none]' ,
4753 ' Can also be specified with the env variable NODE_HTTP_SERVER_PASSWORD' ,
4854 '' ,
49- ' -S --ssl Enable https. ' ,
50- ' -C --cert Path to ssl cert file (default: cert.pem). ' ,
51- ' -K --key Path to ssl key file (default: key.pem). ' ,
55+ ' -S --tls -- ssl Enable secure request serving with TLS/SSL (HTTPS) ' ,
56+ ' -C --cert Path to TLS cert file (default: cert.pem)' ,
57+ ' -K --key Path to TLS key file (default: key.pem)' ,
5258 '' ,
5359 ' -r --robots Respond to /robots.txt [User-agent: *\\nDisallow: /]' ,
5460 ' --no-dotfiles Do not show dotfiles' ,
@@ -61,12 +67,26 @@ if (argv.h || argv.help) {
6167
6268var port = argv . p || argv . port || parseInt ( process . env . PORT , 10 ) ,
6369 host = argv . a || '0.0.0.0' ,
64- ssl = argv . S || argv . ssl ,
70+ tls = argv . S || argv . tls ,
6571 proxy = argv . P || argv . proxy ,
72+ proxyOptions = argv [ 'proxy-options' ] ,
6673 utc = argv . U || argv . utc ,
6774 version = argv . v || argv . version ,
6875 logger ;
6976
77+ var proxyOptionsBooleanProps = [
78+ 'ws' , 'xfwd' , 'secure' , 'toProxy' , 'prependPath' , 'ignorePath' , 'changeOrigin' ,
79+ 'preserveHeaderKeyCase' , 'followRedirects' , 'selfHandleResponse'
80+ ] ;
81+
82+ if ( proxyOptions ) {
83+ Object . keys ( proxyOptions ) . forEach ( function ( key ) {
84+ if ( proxyOptionsBooleanProps . indexOf ( key ) > - 1 ) {
85+ proxyOptions [ key ] = proxyOptions [ key ] . toLowerCase ( ) === 'true' ;
86+ }
87+ } ) ;
88+ }
89+
7090if ( ! argv . s && ! argv . silent ) {
7191 logger = {
7292 info : console . log ,
@@ -128,6 +148,7 @@ function listen(port) {
128148 ext : argv . e || argv . ext ,
129149 logFn : logger . request ,
130150 proxy : proxy ,
151+ proxyOptions : proxyOptions ,
131152 showDotfiles : argv . dotfiles ,
132153 mimetypes : argv . mimetypes ,
133154 username : argv . username || process . env . NODE_HTTP_SERVER_USERNAME ,
@@ -151,7 +172,7 @@ function listen(port) {
151172 }
152173 }
153174
154- if ( ssl ) {
175+ if ( tls ) {
155176 options . https = {
156177 cert : argv . C || argv . cert || 'cert.pem' ,
157178 key : argv . K || argv . key || 'key.pem'
@@ -174,16 +195,18 @@ function listen(port) {
174195
175196 var server = httpServer . createServer ( options ) ;
176197 server . listen ( port , host , function ( ) {
177- var protocol = ssl ? 'https://' : 'http://' ;
198+ var protocol = tls ? 'https://' : 'http://' ;
178199
179- logger . info ( [ colors . yellow ( 'Starting up http-server, serving ' ) ,
200+ logger . info ( [
201+ colors . yellow ( 'Starting up http-server, serving ' ) ,
180202 colors . cyan ( server . root ) ,
181- ssl ? ( colors . yellow ( ' through' ) + colors . cyan ( ' https' ) ) : ''
203+ tls ? ( colors . yellow ( ' through' ) + colors . cyan ( ' https' ) ) : ''
182204 ] . join ( '' ) ) ;
183205
184206 logger . info ( [ colors . yellow ( '\nhttp-server version: ' ) , colors . cyan ( require ( '../package.json' ) . version ) ] . join ( '' ) ) ;
185207
186- logger . info ( [ colors . yellow ( '\nhttp-server settings: ' ) ,
208+ logger . info ( [
209+ colors . yellow ( '\nhttp-server settings: ' ) ,
187210 ( [ colors . yellow ( 'CORS: ' ) , argv . cors ? colors . cyan ( argv . cors ) : colors . red ( 'disabled' ) ] . join ( '' ) ) ,
188211 ( [ colors . yellow ( 'Cache: ' ) , argv . c ? ( argv . c === '-1' ? colors . red ( 'disabled' ) : colors . cyan ( argv . c + ' seconds' ) ) : colors . cyan ( '3600 seconds' ) ] . join ( '' ) ) ,
189212 ( [ colors . yellow ( 'Connection Timeout: ' ) , argv . t === '0' ? colors . red ( 'disabled' ) : ( argv . t ? colors . cyan ( argv . t + ' seconds' ) : colors . cyan ( '120 seconds' ) ) ] . join ( '' ) ) ,
@@ -209,7 +232,12 @@ function listen(port) {
209232 }
210233
211234 if ( typeof proxy === 'string' ) {
212- logger . info ( 'Unhandled requests will be served from: ' + proxy ) ;
235+ if ( proxyOptions ) {
236+ logger . info ( 'Unhandled requests will be served from: ' + proxy + '. Options: ' + JSON . stringify ( proxyOptions ) ) ;
237+ }
238+ else {
239+ logger . info ( 'Unhandled requests will be served from: ' + proxy ) ;
240+ }
213241 }
214242
215243 logger . info ( 'Hit CTRL-C to stop the server' ) ;
0 commit comments