diff --git a/README.md b/README.md index 9ce84be8..051d4238 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,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 a246e60d..707c2454 100755 --- a/bin/http-server +++ b/bin/http-server @@ -32,6 +32,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).', @@ -98,10 +99,17 @@ function listen(port) { autoIndex: argv.i, robots: argv.r || argv.robots, ext: argv.e || argv.ext, - logFn: logger.request, - proxy: proxy + logFn: logger.request }; + 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 8d849109..02bc969c 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -98,16 +98,13 @@ function HttpServer(options) { autoIndex: this.autoIndex, defaultExt: this.ext, 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); }); }