Skip to content

Commit b5a1c33

Browse files
authored
Merge branch 'master' into qr
2 parents a569197 + 35ff346 commit b5a1c33

File tree

14 files changed

+1278
-1444
lines changed

14 files changed

+1278
-1444
lines changed

.github/workflows/node.js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
node-version: [10.x, 12.x, 14.x, 16.x]
20+
node-version: [12.x, 14.x, 16.x]
2121
os: [ubuntu-latest, macOS-latest, windows-latest]
2222

2323
steps:

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ This will install `http-server` globally so that it may be run from the command
5858
|`-U` or `--utc` |Use UTC time format in log messages.| |
5959
|`--log-ip` |Enable logging of the client's IP address |`false` |
6060
|`-P` or `--proxy` |Proxies all requests which can't be resolved locally to the given url. e.g.: -P http://someurl.com | |
61+
|`--proxy-options` Pass proxy [options](https://github.com/http-party/node-http-proxy#options) using nested dotted objects. e.g.: --proxy-options.secure false
62+
6163
|`--username` |Username for basic authentication | |
6264
|`--password` |Password for basic authentication | |
6365
|`-S` or `--ssl` |Enable https.| |

bin/http-server

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6465
var 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

7287
if (!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) {

doc/http-server.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ Enable logging of the client IP address.
8585
.BI \-P ", " \-\-proxy
8686
Fallback proxy if the request cannot be resolved.
8787

88+
.TP
89+
.BI \-\-proxy\-options
90+
Pass proxy options using nested dotted objects.
91+
8892
.TP
8993
.BI \-\-username " " \fIUSERNAME\fR
9094
Username for basic authentication.

lib/http-server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ function HttpServer(options) {
141141
}));
142142

143143
if (typeof options.proxy === 'string') {
144-
var proxy = httpProxy.createProxyServer({});
144+
var proxyOptions = options.proxyOptions || {};
145+
var proxy = httpProxy.createProxyServer(proxyOptions);
145146
before.push(function (req, res) {
146147
proxy.web(req, res, {
147148
target: options.proxy,

0 commit comments

Comments
 (0)