diff --git a/README.md b/README.md index 41e743f7e..bc71d9a9a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ This will install `http-server` globally so that it may be run from the command `-P` or `--proxy` Proxies all requests which can't be resolved locally to the given url. e.g.: -P http://someurl.com +`--proxy-secure` Verify SSL certificates for proxied requests (defaults to true) + `-S` or `--ssl` Enable https. `-C` or `--cert` Path to ssl cert file (default: cert.pem). diff --git a/bin/http-server b/bin/http-server index 926e0dd75..b7608df0b 100755 --- a/bin/http-server +++ b/bin/http-server @@ -33,6 +33,7 @@ if (argv.h || argv.help) { ' -U --utc Use UTC time format in log messages.', '', ' -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com', + ' --proxy-secure Verify proxied SSL certificates [true]', '', ' -S --ssl Enable https.', ' -C --cert Path to ssl cert file (default: cert.pem).', @@ -102,10 +103,17 @@ function listen(port) { robots: argv.r || argv.robots, ext: argv.e || argv.ext, logFn: logger.request, - proxy: proxy, showDotfiles: argv.dotfiles }; + if (proxy) { + options.proxy = { + target: proxy, + secure: argv['proxy-secure'] !== 'false', + changeOrigin: true + }; + } + if (argv.cors) { options.cors = true; if (typeof argv.cors === 'string') { diff --git a/lib/http-server.js b/lib/http-server.js index 7e3e06df1..0c80703d3 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -102,16 +102,13 @@ function HttpServer(options) { defaultExt: this.ext, gzip: this.gzip, contentType: this.contentType, - handleError: typeof options.proxy !== 'string' + handleError: typeof options.proxy !== 'object' })); - if (typeof options.proxy === 'string') { + if (options.proxy) { var proxy = httpProxy.createProxyServer({}); before.push(function (req, res) { - proxy.web(req, res, { - target: options.proxy, - changeOrigin: true - }); + proxy.web(req, res, options.proxy); }); } diff --git a/package.json b/package.json index f42a2079b..4096cd126 100644 --- a/package.json +++ b/package.json @@ -67,9 +67,9 @@ ], "dependencies": { "colors": "1.0.3", + "http-proxy": "^v1.11.1", "corser": "~2.0.0", "ecstatic": "^2.0.0", - "http-proxy": "^1.8.1", "opener": "~1.4.0", "optimist": "0.6.x", "portfinder": "^1.0.13",