@@ -7,9 +7,14 @@ var colors = require('colors/safe'),
7
7
httpServer = require ( '../lib/http-server' ) ,
8
8
portfinder = require ( 'portfinder' ) ,
9
9
opener = require ( 'opener' ) ,
10
+
10
11
fs = require ( 'fs' ) ,
11
- argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ,
12
12
url = require ( 'url' ) ;
13
+ var argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) , {
14
+ alias : {
15
+ tls : 'ssl'
16
+ }
17
+ } ) ;
13
18
var ifaces = os . networkInterfaces ( ) ;
14
19
15
20
process . title = 'http-server' ;
@@ -39,16 +44,17 @@ if (argv.h || argv.help) {
39
44
' -U --utc Use UTC time format in log messages.' ,
40
45
' --log-ip Enable logging of the client\'s IP address' ,
41
46
'' ,
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' ,
43
49
'' ,
44
50
' --username Username for basic authentication [none]' ,
45
51
' Can also be specified with the env variable NODE_HTTP_SERVER_USERNAME' ,
46
52
' --password Password for basic authentication [none]' ,
47
53
' Can also be specified with the env variable NODE_HTTP_SERVER_PASSWORD' ,
48
54
'' ,
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)' ,
52
58
'' ,
53
59
' -r --robots Respond to /robots.txt [User-agent: *\\nDisallow: /]' ,
54
60
' --no-dotfiles Do not show dotfiles' ,
@@ -61,12 +67,26 @@ if (argv.h || argv.help) {
61
67
62
68
var port = argv . p || argv . port || parseInt ( process . env . PORT , 10 ) ,
63
69
host = argv . a || '0.0.0.0' ,
64
- ssl = argv . S || argv . ssl ,
70
+ tls = argv . S || argv . tls ,
65
71
proxy = argv . P || argv . proxy ,
72
+ proxyOptions = argv [ 'proxy-options' ] ,
66
73
utc = argv . U || argv . utc ,
67
74
version = argv . v || argv . version ,
68
75
logger ;
69
76
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
+
70
90
if ( ! argv . s && ! argv . silent ) {
71
91
logger = {
72
92
info : console . log ,
@@ -128,6 +148,7 @@ function listen(port) {
128
148
ext : argv . e || argv . ext ,
129
149
logFn : logger . request ,
130
150
proxy : proxy ,
151
+ proxyOptions : proxyOptions ,
131
152
showDotfiles : argv . dotfiles ,
132
153
mimetypes : argv . mimetypes ,
133
154
username : argv . username || process . env . NODE_HTTP_SERVER_USERNAME ,
@@ -151,7 +172,7 @@ function listen(port) {
151
172
}
152
173
}
153
174
154
- if ( ssl ) {
175
+ if ( tls ) {
155
176
options . https = {
156
177
cert : argv . C || argv . cert || 'cert.pem' ,
157
178
key : argv . K || argv . key || 'key.pem'
@@ -174,16 +195,18 @@ function listen(port) {
174
195
175
196
var server = httpServer . createServer ( options ) ;
176
197
server . listen ( port , host , function ( ) {
177
- var protocol = ssl ? 'https://' : 'http://' ;
198
+ var protocol = tls ? 'https://' : 'http://' ;
178
199
179
- logger . info ( [ colors . yellow ( 'Starting up http-server, serving ' ) ,
200
+ logger . info ( [
201
+ colors . yellow ( 'Starting up http-server, serving ' ) ,
180
202
colors . cyan ( server . root ) ,
181
- ssl ? ( colors . yellow ( ' through' ) + colors . cyan ( ' https' ) ) : ''
203
+ tls ? ( colors . yellow ( ' through' ) + colors . cyan ( ' https' ) ) : ''
182
204
] . join ( '' ) ) ;
183
205
184
206
logger . info ( [ colors . yellow ( '\nhttp-server version: ' ) , colors . cyan ( require ( '../package.json' ) . version ) ] . join ( '' ) ) ;
185
207
186
- logger . info ( [ colors . yellow ( '\nhttp-server settings: ' ) ,
208
+ logger . info ( [
209
+ colors . yellow ( '\nhttp-server settings: ' ) ,
187
210
( [ colors . yellow ( 'CORS: ' ) , argv . cors ? colors . cyan ( argv . cors ) : colors . red ( 'disabled' ) ] . join ( '' ) ) ,
188
211
( [ colors . yellow ( 'Cache: ' ) , argv . c ? ( argv . c === '-1' ? colors . red ( 'disabled' ) : colors . cyan ( argv . c + ' seconds' ) ) : colors . cyan ( '3600 seconds' ) ] . join ( '' ) ) ,
189
212
( [ 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) {
209
232
}
210
233
211
234
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
+ }
213
241
}
214
242
215
243
logger . info ( 'Hit CTRL-C to stop the server' ) ;
0 commit comments