Skip to content

Commit b9304ee

Browse files
authored
Merge branch 'master' into master
2 parents b80f3d3 + 622302e commit b9304ee

25 files changed

+929
-679
lines changed

.github/ISSUE_TEMPLATE

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/bug-report.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
---
5+
6+
<!-- Describe the issue briefly here. -->
7+
8+
#### Environment Versions
9+
10+
1. OS Type
11+
1. Node version: `$ node --version`
12+
1. http-server version: `$ http-server --version`
13+
14+
#### Steps to reproduce
15+
16+
<!-- Include the actual command -->
17+
18+
1. ...
19+
2. ...
20+
3. ...
21+
22+
#### Expected result
23+
24+
...
25+
26+
#### Actual result
27+
28+
<!-- Include full output and/or stack trace -->
29+
30+
...
31+
32+
#### Other information
33+
34+
<!-- Include related issues, suggestions for a fix or further debug information, etc. -->
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
---
5+
6+
#### What's the problem this feature will solve?
7+
8+
<!-- What are you trying to do, that you are unable to achieve with http-server as it currently stands? -->
9+
10+
#### Describe the solution you'd like
11+
12+
<!-- A clear and concise description of what you want to happen. -->
13+
14+
<!-- Provide examples of real-world use cases that this would enable and how it solves the problem described above. -->
15+
16+
#### Alternative Solutions
17+
18+
<!-- Have you tried to workaround the problem using http-server or other tools? Or a different approach to solving this issue? Please elaborate here. -->
19+
20+
#### Additional context
21+
22+
<!-- Add any other context, links, etc. about the feature here. -->

.github/PULL_REQUEST_TEMPLATE

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--- Describe the changes here. --->
2+
3+
##### Relevant issues
4+
5+
<!--
6+
Link to the issue(s) this pull request fixes here, if applicable: "Fixes #xxx" or "Resolves #xxx"
7+
8+
If your PR fixes multiple issues, list them individually like "Fixes #xx1, fixes #xx2, fixes #xx3". This is a quirk of how GitHub links issues.
9+
-->
10+
11+
##### Contributor checklist
12+
13+
- [ ] Provide tests for the changes (unless documentation-only)
14+
- [ ] Documented any new features, CLI switches, etc. (if applicable)
15+
- [ ] Server `--help` output
16+
- [ ] README.md
17+
- [ ] doc/http-server.1 (use the same format as other entries)
18+
- [ ] The pull request is being made against the `master` branch
19+
20+
##### Maintainer checklist
21+
22+
- [ ] Assign a version triage tag
23+
- [ ] Approve tests if applicable

.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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ 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 | |
63-
|`-S` or `--ssl` |Enable https.| |
65+
|`-S`, `--tls` or `--ssl` |Enable secure request serving with TLS/SSL (HTTPS)|`false`|
6466
|`-C` or `--cert` |Path to ssl cert file |`cert.pem` |
6567
|`-K` or `--key` |Path to ssl key file |`key.pem` |
6668
|`-r` or `--robots` | Automatically provide a /robots.txt (The content of which defaults to `User-agent: *\nDisallow: /`) | `false` |

bin/http-server

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ var colors = require('colors/safe'),
77
httpServer = require('../lib/http-server'),
88
portfinder = require('portfinder'),
99
opener = require('opener'),
10+
1011
fs = require('fs'),
11-
argv = require('minimist')(process.argv.slice(2)),
1212
url = require('url');
13+
var argv = require('minimist')(process.argv.slice(2), {
14+
alias: {
15+
tls: 'ssl'
16+
}
17+
});
1318
var ifaces = os.networkInterfaces();
1419

1520
process.title = 'http-server';
@@ -39,16 +44,17 @@ if (argv.h || argv.help) {
3944
' -U --utc Use UTC time format in log messages.',
4045
' --log-ip Enable logging of the client\'s IP address',
4146
'',
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',
4349
'',
4450
' --username Username for basic authentication [none]',
4551
' Can also be specified with the env variable NODE_HTTP_SERVER_USERNAME',
4652
' --password Password for basic authentication [none]',
4753
' Can also be specified with the env variable NODE_HTTP_SERVER_PASSWORD',
4854
'',
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)',
5258
'',
5359
' -r --robots Respond to /robots.txt [User-agent: *\\nDisallow: /]',
5460
' --no-dotfiles Do not show dotfiles',
@@ -61,12 +67,26 @@ if (argv.h || argv.help) {
6167

6268
var port = argv.p || argv.port || parseInt(process.env.PORT, 10),
6369
host = argv.a || '0.0.0.0',
64-
ssl = argv.S || argv.ssl,
70+
tls = argv.S || argv.tls,
6571
proxy = argv.P || argv.proxy,
72+
proxyOptions = argv['proxy-options'],
6673
utc = argv.U || argv.utc,
6774
version = argv.v || argv.version,
6875
logger;
6976

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+
7090
if (!argv.s && !argv.silent) {
7191
logger = {
7292
info: console.log,
@@ -128,6 +148,7 @@ function listen(port) {
128148
ext: argv.e || argv.ext,
129149
logFn: logger.request,
130150
proxy: proxy,
151+
proxyOptions: proxyOptions,
131152
showDotfiles: argv.dotfiles,
132153
mimetypes: argv.mimetypes,
133154
username: argv.username || process.env.NODE_HTTP_SERVER_USERNAME,
@@ -151,7 +172,7 @@ function listen(port) {
151172
}
152173
}
153174

154-
if (ssl) {
175+
if (tls) {
155176
options.https = {
156177
cert: argv.C || argv.cert || 'cert.pem',
157178
key: argv.K || argv.key || 'key.pem'
@@ -174,16 +195,18 @@ function listen(port) {
174195

175196
var server = httpServer.createServer(options);
176197
server.listen(port, host, function () {
177-
var protocol = ssl ? 'https://' : 'http://';
198+
var protocol = tls ? 'https://' : 'http://';
178199

179-
logger.info([colors.yellow('Starting up http-server, serving '),
200+
logger.info([
201+
colors.yellow('Starting up http-server, serving '),
180202
colors.cyan(server.root),
181-
ssl ? (colors.yellow(' through') + colors.cyan(' https')) : ''
203+
tls ? (colors.yellow(' through') + colors.cyan(' https')) : ''
182204
].join(''));
183205

184206
logger.info([colors.yellow('\nhttp-server version: '), colors.cyan(require('../package.json').version)].join(''));
185207

186-
logger.info([colors.yellow('\nhttp-server settings: '),
208+
logger.info([
209+
colors.yellow('\nhttp-server settings: '),
187210
([colors.yellow('CORS: '), argv.cors ? colors.cyan(argv.cors) : colors.red('disabled')].join('')),
188211
([colors.yellow('Cache: '), argv.c ? (argv.c === '-1' ? colors.red('disabled') : colors.cyan(argv.c + ' seconds')) : colors.cyan('3600 seconds')].join('')),
189212
([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) {
209232
}
210233

211234
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+
}
213241
}
214242

215243
logger.info('Hit CTRL-C to stop the server');

doc/http-server.1

Lines changed: 5 additions & 1 deletion
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.
@@ -98,7 +102,7 @@ Can also be specified with the environment variable NODE_HTTP_SERVER_PASSWORD.
98102
Defaults to none.
99103

100104
.TP
101-
.BI \-S ", " \-\-ssl
105+
.BI \-S ", " \-\-tls ", " \-\-ssl
102106
Enable https.
103107

104108
.TP

lib/http-server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ function HttpServer(options) {
3333

3434
if (options.root) {
3535
this.root = options.root;
36-
}
37-
else {
36+
} else {
3837
try {
3938
fs.lstatSync('./public');
4039
this.root = './public';
@@ -141,7 +140,8 @@ function HttpServer(options) {
141140
}));
142141

143142
if (typeof options.proxy === 'string') {
144-
var proxy = httpProxy.createProxyServer({});
143+
var proxyOptions = options.proxyOptions || {};
144+
var proxy = httpProxy.createProxyServer(proxyOptions);
145145
before.push(function (req, res) {
146146
proxy.web(req, res, {
147147
target: options.proxy,

0 commit comments

Comments
 (0)