@@ -41,6 +41,7 @@ if (argv.h || argv.help) {
4141 ' --log-ip Enable logging of the client\'s IP address' ,
4242 '' ,
4343 ' -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com' ,
44+ ' --proxy-options Pass options to proxy using nested dotted objects. e.g.: --proxy-options.secure false' ,
4445 '' ,
4546 ' --username Username for basic authentication [none]' ,
4647 ' Can also be specified with the env variable NODE_HTTP_SERVER_USERNAME' ,
@@ -62,12 +63,26 @@ if (argv.h || argv.help) {
6263}
6364
6465var port = argv . p || argv . port || parseInt ( process . env . PORT , 10 ) ,
65- host = argv . a || '0.0.0.0' ,
66- ssl = argv . S || argv . ssl ,
67- proxy = argv . P || argv . proxy ,
68- utc = argv . U || argv . utc ,
69- version = argv . v || argv . version ,
70- logger ;
66+ host = argv . a || '0.0.0.0' ,
67+ ssl = argv . S || argv . ssl ,
68+ proxy = argv . P || argv . proxy ,
69+ proxyOptions = argv [ 'proxy-options' ] ,
70+ utc = argv . U || argv . utc ,
71+ version = argv . v || argv . version ,
72+ logger ;
73+
74+ var proxyOptionsBooleanProps = [
75+ 'ws' , 'xfwd' , 'secure' , 'toProxy' , 'prependPath' , 'ignorePath' , 'changeOrigin' ,
76+ 'preserveHeaderKeyCase' , 'followRedirects' , 'selfHandleResponse'
77+ ] ;
78+
79+ if ( proxyOptions ) {
80+ Object . keys ( proxyOptions ) . forEach ( function ( key ) {
81+ if ( proxyOptionsBooleanProps . indexOf ( key ) > - 1 ) {
82+ proxyOptions [ key ] = proxyOptions [ key ] . toLowerCase ( ) === 'true' ;
83+ }
84+ } ) ;
85+ }
7186
7287if ( ! argv . s && ! argv . silent ) {
7388 logger = {
@@ -130,6 +145,7 @@ function listen(port) {
130145 ext : argv . e || argv . ext ,
131146 logFn : logger . request ,
132147 proxy : proxy ,
148+ proxyOptions : proxyOptions ,
133149 showDotfiles : argv . dotfiles ,
134150 mimetypes : argv . mimetypes ,
135151 username : argv . username || process . env . NODE_HTTP_SERVER_USERNAME ,
@@ -203,7 +219,12 @@ function listen(port) {
203219 }
204220
205221 if ( typeof proxy === 'string' ) {
206- logger . info ( 'Unhandled requests will be served from: ' + proxy ) ;
222+ if ( proxyOptions ) {
223+ logger . info ( 'Unhandled requests will be served from: ' + proxy + '. Options: ' + JSON . stringify ( proxyOptions ) ) ;
224+ }
225+ else {
226+ logger . info ( 'Unhandled requests will be served from: ' + proxy ) ;
227+ }
207228 }
208229 if ( options . showQR ) {
209230 qrcode . generate ( plainIp , { small : true } , function ( qr ) {
0 commit comments