Skip to content

Commit cb0b601

Browse files
committed
Merge branch 'master' into allow-pem-passphrase
2 parents d21714f + 96aa6e9 commit cb0b601

26 files changed

+1645
-1557
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/release-drafter.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name-template: 'v$RESOLVED_VERSION'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
4+
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
5+
change-title-escapes: '\<*_&'
6+
7+
categories:
8+
- title: 'Breaking changes'
9+
labels:
10+
- 'major version'
11+
- title: 'Features and enhancements'
12+
labels:
13+
- 'feature'
14+
- 'enhancement'
15+
- title: 'Bug Fixes'
16+
labels:
17+
- 'fix'
18+
- 'bug'
19+
- title: 'Other changes'
20+
labels:
21+
- 'dependencies'
22+
- 'documentation'
23+
24+
exclude-labels:
25+
- "skip-changelog"
26+
- "maintenance"
27+
- "trivial"
28+
29+
version-resolver:
30+
major:
31+
labels:
32+
- 'major version'
33+
minor:
34+
labels:
35+
- 'minor version'
36+
patch:
37+
labels:
38+
- 'patch version'
39+
default: patch
40+
41+
template: |
42+
$CHANGES

.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:

.github/workflows/release-drafter.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: release-drafter
2+
3+
on:
4+
push:
5+
# branches to consider in the event; optional, defaults to all
6+
branches:
7+
- master
8+
9+
jobs:
10+
update_release_draft:
11+
permissions:
12+
contents: write
13+
pull-requests: read
14+
if: github.repository == 'http-party/http-server'
15+
runs-on: ubuntu-latest
16+
steps:
17+
# Drafts your next release notes as pull requests are merged into master
18+
- uses: release-drafter/release-drafter@v5
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ 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 |
6162
|`--username` |Username for basic authentication | |
6263
|`--password` |Password for basic authentication | |
63-
|`-S` or `--ssl` |Enable https.| |
64+
|`-S`, `--tls` or `--ssl` |Enable secure request serving with TLS/SSL (HTTPS)|`false`|
6465
|`-C` or `--cert` |Path to ssl cert file |`cert.pem` |
6566
|`-K` or `--key` |Path to ssl key file |`key.pem` |
6667
|`-r` or `--robots` | Automatically provide a /robots.txt (The content of which defaults to `User-agent: *\nDisallow: /`) | `false` |

bin/http-server

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +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));
12+
url = require('url');
13+
var argv = require('minimist')(process.argv.slice(2), {
14+
alias: {
15+
tls: 'ssl'
16+
}
17+
});
1218
var ifaces = os.networkInterfaces();
1319

1420
process.title = 'http-server';
@@ -38,16 +44,17 @@ if (argv.h || argv.help) {
3844
' -U --utc Use UTC time format in log messages.',
3945
' --log-ip Enable logging of the client\'s IP address',
4046
'',
41-
' -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',
4249
'',
4350
' --username Username for basic authentication [none]',
4451
' Can also be specified with the env variable NODE_HTTP_SERVER_USERNAME',
4552
' --password Password for basic authentication [none]',
4653
' Can also be specified with the env variable NODE_HTTP_SERVER_PASSWORD',
4754
'',
48-
' -S --ssl Enable https.',
49-
' -C --cert Path to ssl cert file (default: cert.pem).',
50-
' -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)',
5158
'',
5259
' -r --robots Respond to /robots.txt [User-agent: *\\nDisallow: /]',
5360
' --no-dotfiles Do not show dotfiles',
@@ -60,13 +67,27 @@ if (argv.h || argv.help) {
6067

6168
var port = argv.p || argv.port || parseInt(process.env.PORT, 10),
6269
host = argv.a || '0.0.0.0',
63-
ssl = argv.S || argv.ssl,
70+
tls = argv.S || argv.tls,
6471
sslPassphrase = process.env.NODE_HTTP_SERVER_SSL_PASSPHRASE,
6572
proxy = argv.P || argv.proxy,
73+
proxyOptions = argv['proxy-options'],
6674
utc = argv.U || argv.utc,
6775
version = argv.v || argv.version,
6876
logger;
6977

78+
var proxyOptionsBooleanProps = [
79+
'ws', 'xfwd', 'secure', 'toProxy', 'prependPath', 'ignorePath', 'changeOrigin',
80+
'preserveHeaderKeyCase', 'followRedirects', 'selfHandleResponse'
81+
];
82+
83+
if (proxyOptions) {
84+
Object.keys(proxyOptions).forEach(function (key) {
85+
if (proxyOptionsBooleanProps.indexOf(key) > -1) {
86+
proxyOptions[key] = proxyOptions[key].toLowerCase() === 'true';
87+
}
88+
});
89+
}
90+
7091
if (!argv.s && !argv.silent) {
7192
logger = {
7293
info: console.log,
@@ -128,6 +149,7 @@ function listen(port) {
128149
ext: argv.e || argv.ext,
129150
logFn: logger.request,
130151
proxy: proxy,
152+
proxyOptions: proxyOptions,
131153
showDotfiles: argv.dotfiles,
132154
mimetypes: argv.mimetypes,
133155
username: argv.username || process.env.NODE_HTTP_SERVER_USERNAME,
@@ -141,7 +163,17 @@ function listen(port) {
141163
}
142164
}
143165

144-
if (ssl) {
166+
if (proxy) {
167+
try {
168+
new url.URL(proxy)
169+
}
170+
catch (err) {
171+
logger.info(colors.red('Error: Invalid proxy url'));
172+
process.exit(1);
173+
}
174+
}
175+
176+
if (tls) {
145177
options.https = {
146178
cert: argv.C || argv.cert || 'cert.pem',
147179
key: argv.K || argv.key || 'key.pem',
@@ -165,16 +197,18 @@ function listen(port) {
165197

166198
var server = httpServer.createServer(options);
167199
server.listen(port, host, function () {
168-
var protocol = ssl ? 'https://' : 'http://';
200+
var protocol = tls ? 'https://' : 'http://';
169201

170-
logger.info([colors.yellow('Starting up http-server, serving '),
202+
logger.info([
203+
colors.yellow('Starting up http-server, serving '),
171204
colors.cyan(server.root),
172-
ssl ? (colors.yellow(' through') + colors.cyan(' https')) : ''
205+
tls ? (colors.yellow(' through') + colors.cyan(' https')) : ''
173206
].join(''));
174207

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

177-
logger.info([colors.yellow('\nhttp-server settings: '),
210+
logger.info([
211+
colors.yellow('\nhttp-server settings: '),
178212
([colors.yellow('CORS: '), argv.cors ? colors.cyan(argv.cors) : colors.red('disabled')].join('')),
179213
([colors.yellow('Cache: '), argv.c ? (argv.c === '-1' ? colors.red('disabled') : colors.cyan(argv.c + ' seconds')) : colors.cyan('3600 seconds')].join('')),
180214
([colors.yellow('Connection Timeout: '), argv.t === '0' ? colors.red('disabled') : (argv.t ? colors.cyan(argv.t + ' seconds') : colors.cyan('120 seconds'))].join('')),
@@ -200,7 +234,12 @@ function listen(port) {
200234
}
201235

202236
if (typeof proxy === 'string') {
203-
logger.info('Unhandled requests will be served from: ' + proxy);
237+
if (proxyOptions) {
238+
logger.info('Unhandled requests will be served from: ' + proxy + '. Options: ' + JSON.stringify(proxyOptions));
239+
}
240+
else {
241+
logger.info('Unhandled requests will be served from: ' + proxy);
242+
}
204243
}
205244

206245
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

0 commit comments

Comments
 (0)