Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ with the provided Dockerfile.
|`--log-ip` |Enable logging of the client's IP address |`false` |
|`-P` or `--proxy` |Proxies all requests which can't be resolved locally to the given url. e.g.: -P http://someurl.com | |
|`--proxy-options` |Pass proxy [options](https://github.com/http-party/node-http-proxy#options) using nested dotted objects. e.g.: --proxy-options.secure false | |
|`--proxy-config` |Pass in `.json` configuration file. e.g.: `./path/to/config.json` | |
|`--proxy-config` |Pass in `.json` configuration file or stringified JSON. e.g.: `./path/to/config.json` | |
|`--proxy-all` |Forward every request to the proxy target instead of serving local files|`false`|
|`--proxy-options` |Pass proxy [options](https://github.com/http-party/node-http-proxy#options) using nested dotted objects. e.g.: --proxy-options.secure false |
|`--username` |Username for basic authentication | |
|`--password` |Password for basic authentication | |
|`-S`, `--tls` or `--ssl` |Enable secure request serving with TLS/SSL (HTTPS)|`false`|
Expand Down
10 changes: 10 additions & 0 deletions bin/http-server
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ if (argv.h || argv.help) {
' --proxy-all Send every request to the proxy target instead of serving local files',
' --proxy-options Pass options to proxy using nested dotted objects. e.g.: --proxy-options.secure false',
' --proxy-config Pass in .json configuration file. e.g.: ./path/to/config.json',
' --websocket Enable websocket proxy',
'',
' --username Username for basic authentication [none]',
' Can also be specified with the env variable NODE_HTTP_SERVER_USERNAME',
Expand All @@ -90,6 +91,8 @@ var port = argv.p || argv.port || parseInt(process.env.PORT, 10),
proxy = argv.P || argv.proxy,
proxyOptions = argv['proxy-options'],
proxyConfig = argv['proxy-config'],
websocket = argv.websocket,
proxyAll = Boolean(argv['proxy-all']),
utc = argv.U || argv.utc,
version = argv.v || argv.version,
baseDir = argv['base-dir'],
Expand Down Expand Up @@ -178,6 +181,7 @@ function listen(port) {
proxy: proxy,
proxyOptions: proxyOptions,
proxyConfig: proxyConfig,
proxyAll: proxyAll,
showDotfiles: argv.dotfiles,
mimetypes: argv.mimetypes,
contentType: argv['content-type'],
Expand Down Expand Up @@ -254,6 +258,12 @@ function listen(port) {
proxyOptions = undefined;
}

// TODO: handle this in respect of proxyConfig
if (proxyAll && !proxy) {
logger.info(chalk.red('Error: --proxy-all requires --proxy to be set'));
process.exit(1);
}

if (tls) {
options.https = {
cert: argv.C || argv.cert || 'cert.pem',
Expand Down
18 changes: 18 additions & 0 deletions lib/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ function HttpServer(options) {
handleError: typeof options.proxy !== 'string'
}));

if (!proxyAll) {
before.push(httpServerCore({
root: this.root,
baseDir: options.baseDir,
cache: this.cache,
showDir: this.showDir,
showDotfiles: this.showDotfiles,
autoIndex: this.autoIndex,
defaultExt: this.ext,
gzip: this.gzip,
brotli: this.brotli,
forceContentEncoding: this.forceContentEncoding,
contentType: this.contentType,
mimetypes: options.mimetypes,
handleError: typeof options.proxy !== 'string'
}));
}

if (typeof options.proxy === 'string') {
var proxyOptions = options.proxyOptions || {};
var proxy = httpProxy.createProxyServer({
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.