Skip to content

Commit 3983e59

Browse files
authored
Merge branch 'master' into qr
2 parents b5a1c33 + 86e8978 commit 3983e59

File tree

13 files changed

+154
-129
lines changed

13 files changed

+154
-129
lines changed

.github/ISSUE_TEMPLATE

Lines changed: 0 additions & 18 deletions
This file was deleted.
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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ This will install `http-server` globally so that it may be run from the command
6262

6363
|`--username` |Username for basic authentication | |
6464
|`--password` |Password for basic authentication | |
65-
|`-S` or `--ssl` |Enable https.| |
65+
|`-S`, `--tls` or `--ssl` |Enable secure request serving with TLS/SSL (HTTPS)|`false`|
6666
|`-C` or `--cert` |Path to ssl cert file |`cert.pem` |
6767
|`-K` or `--key` |Path to ssl key file |`key.pem` |
6868
|`-Q` or `--qr-code` |Show QR code for public IP | |,

bin/http-server

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
'use strict';
44

5-
var colors = require('colors/safe'),
6-
os = require('os'),
7-
httpServer = require('../lib/http-server'),
8-
portfinder = require('portfinder'),
9-
opener = require('opener'),
10-
fs = require('fs'),
11-
argv = require('minimist')(process.argv.slice(2)),
12-
qrcode = require('qrcode-terminal');
5+
var colors = require('colors/safe'),
6+
os = require('os'),
7+
httpServer = require('../lib/http-server'),
8+
portfinder = require('portfinder'),
9+
opener = require('opener'),
10+
fs = require('fs');
11+
var argv = require('minimist')(process.argv.slice(2), {
12+
alias: {
13+
tls: 'ssl'
14+
}
15+
});
1316
var ifaces = os.networkInterfaces();
1417
var plainIp;
1518

@@ -40,7 +43,7 @@ if (argv.h || argv.help) {
4043
' -U --utc Use UTC time format in log messages.',
4144
' --log-ip Enable logging of the client\'s IP address',
4245
'',
43-
' -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com',
46+
' -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com',
4447
' --proxy-options Pass options to proxy using nested dotted objects. e.g.: --proxy-options.secure false',
4548
'',
4649
' --username Username for basic authentication [none]',
@@ -64,7 +67,7 @@ if (argv.h || argv.help) {
6467

6568
var port = argv.p || argv.port || parseInt(process.env.PORT, 10),
6669
host = argv.a || '0.0.0.0',
67-
ssl = argv.S || argv.ssl,
70+
tls = argv.S || argv.tls,
6871
proxy = argv.P || argv.proxy,
6972
proxyOptions = argv['proxy-options'],
7073
utc = argv.U || argv.utc,
@@ -160,7 +163,7 @@ function listen(port) {
160163
}
161164
}
162165

163-
if (ssl) {
166+
if (tls) {
164167
options.https = {
165168
cert: argv.C || argv.cert || 'cert.pem',
166169
key: argv.K || argv.key || 'key.pem'
@@ -183,24 +186,26 @@ function listen(port) {
183186

184187
var server = httpServer.createServer(options);
185188
server.listen(port, host, function () {
186-
var protocol = ssl ? 'https://' : 'http://';
189+
var protocol = tls ? 'https://' : 'http://';
187190

188-
logger.info([colors.yellow('Starting up http-server, serving '),
189-
colors.cyan(server.root),
190-
ssl ? (colors.yellow(' through') + colors.cyan(' https')) : ''
191+
logger.info([
192+
colors.yellow('Starting up http-server, serving '),
193+
colors.cyan(server.root),
194+
tls ? (colors.yellow(' through') + colors.cyan(' https')) : ''
191195
].join(''));
192196

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

195-
logger.info([colors.yellow('\nhttp-server settings: '),
196-
([colors.yellow('CORS: '), argv.cors ? colors.cyan(argv.cors) : colors.red('disabled')].join('')),
197-
([colors.yellow('Cache: '), argv.c ? (argv.c === '-1' ? colors.red('disabled') : colors.cyan(argv.c + ' seconds')) : colors.cyan('3600 seconds')].join('')),
198-
([colors.yellow('Connection Timeout: '), argv.t === '0' ? colors.red('disabled') : (argv.t ? colors.cyan(argv.t + ' seconds') : colors.cyan('120 seconds'))].join('')),
199-
([colors.yellow('Directory Listings: '), argv.d ? colors.red('not visible') : colors.cyan('visible')].join('')),
200-
([colors.yellow('AutoIndex: '), argv.i ? colors.red('not visible') : colors.cyan('visible')].join('')),
201-
([colors.yellow('Serve GZIP Files: '), argv.g || argv.gzip ? colors.cyan('true') : colors.red('false')].join('')),
202-
([colors.yellow('Serve Brotli Files: '), argv.b || argv.brotli ? colors.cyan('true') : colors.red('false')].join('')),
203-
([colors.yellow('Default File Extension: '), argv.e ? colors.cyan(argv.e) : (argv.ext ? colors.cyan(argv.ext) : colors.red('none'))].join(''))
199+
logger.info([
200+
colors.yellow('\nhttp-server settings: '),
201+
([colors.yellow('CORS: '), argv.cors ? colors.cyan(argv.cors) : colors.red('disabled')].join('')),
202+
([colors.yellow('Cache: '), argv.c ? (argv.c === '-1' ? colors.red('disabled') : colors.cyan(argv.c + ' seconds')) : colors.cyan('3600 seconds')].join('')),
203+
([colors.yellow('Connection Timeout: '), argv.t === '0' ? colors.red('disabled') : (argv.t ? colors.cyan(argv.t + ' seconds') : colors.cyan('120 seconds'))].join('')),
204+
([colors.yellow('Directory Listings: '), argv.d ? colors.red('not visible') : colors.cyan('visible')].join('')),
205+
([colors.yellow('AutoIndex: '), argv.i ? colors.red('not visible') : colors.cyan('visible')].join('')),
206+
([colors.yellow('Serve GZIP Files: '), argv.g || argv.gzip ? colors.cyan('true') : colors.red('false')].join('')),
207+
([colors.yellow('Serve Brotli Files: '), argv.b || argv.brotli ? colors.cyan('true') : colors.red('false')].join('')),
208+
([colors.yellow('Default File Extension: '), argv.e ? colors.cyan(argv.e) : (argv.ext ? colors.cyan(argv.ext) : colors.red('none'))].join(''))
204209
].join('\n'));
205210

206211
logger.info(colors.yellow('\nAvailable on:'));

doc/http-server.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Can also be specified with the environment variable NODE_HTTP_SERVER_PASSWORD.
102102
Defaults to none.
103103

104104
.TP
105-
.BI \-S ", " \-\-ssl
105+
.BI \-S ", " \-\-tls ", " \-\-ssl
106106
Enable https.
107107

108108
.TP

lib/core/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function shouldCompressBrotli(req) {
5555

5656
function hasGzipId12(gzipped, cb) {
5757
const stream = fs.createReadStream(gzipped, { start: 0, end: 1 });
58-
let buffer = Buffer('');
58+
let buffer = Buffer.from('');
5959
let hasBeenCalled = false;
6060

6161
stream.on('data', (chunk) => {
@@ -318,6 +318,9 @@ module.exports = function createMiddleware(_dir, _options) {
318318
stream.on('error', (err) => {
319319
status['500'](res, next, { error: err });
320320
});
321+
stream.on('close', () => {
322+
stream.destroy();
323+
})
321324
}
322325

323326

lib/http-server.js

Lines changed: 1 addition & 2 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';

0 commit comments

Comments
 (0)