Skip to content

Commit e3e4241

Browse files
authored
Add -T / --title parameter (#939)
Closes #883
1 parent 0643dab commit e3e4241

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ with the provided Dockerfile.
7878
|`-o [path]` |Open browser window after starting the server. Optionally provide a URL path to open. e.g.: -o /other/dir/ | |
7979
|`-c` |Set cache time (in seconds) for cache-control max-age header, e.g. `-c10` for 10 seconds. To disable caching, use `-c-1`.|`3600` |
8080
|`-t` |Connection timeout in seconds, e.g. `-t60` for 1 minute. To disable timeout, use `-t0`.|`120` |
81+
|`-T` or `--title` |Custom title suffix for the terminal window. The title will be "http-server PORT [TITLE]".| |
8182
|`-U` or `--utc` |Use UTC time format in log messages.| |
8283
|`--log-ip` |Enable logging of the client's IP address |`false` |
8384
|`-P` or `--proxy` |Proxies all requests which can't be resolved locally to the given url. e.g.: -P http://someurl.com | |

bin/http-server

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ var argv = require('minimist')(process.argv.slice(2), {
2121

2222
var ifaces = os.networkInterfaces();
2323

24-
process.title = 'http-server';
25-
2624
if (argv.h || argv.help) {
2725
console.log([
2826
'usage: http-server [path] [options]',
@@ -64,6 +62,8 @@ if (argv.h || argv.help) {
6462
' To disable caching, use -c-1.',
6563
' -t Connection timeout in seconds [120], e.g. -t60 for 1 minute.',
6664
' To disable timeout, use -t0.',
65+
' -T --title Custom title suffix for the terminal window [none]',
66+
' The terminal title will be "http-server PORT [TITLE]"',
6767
' -U --utc Use UTC time format in log messages.',
6868
' --log-ip Enable logging of the client\'s IP address',
6969
'',
@@ -94,6 +94,7 @@ if (argv.h || argv.help) {
9494
var port = argv.p || argv.port || parseInt(process.env.PORT, 10),
9595
host = argv.a || '::',
9696
tls = argv.S || argv.tls,
97+
title = argv.T || argv.title,
9798
sslPassphrase = process.env.NODE_HTTP_SERVER_SSL_PASSPHRASE,
9899
proxy = argv.P || argv.proxy,
99100
proxyOptions = argv['proxy-options'],
@@ -311,6 +312,9 @@ function listen(port) {
311312

312313
var server = httpServer.createServer(options);
313314
server.listen(port, host, function () {
315+
// Set process title with port and optional custom suffix
316+
process.title = 'http-server ' + port + (title ? ' ' + title : '');
317+
314318
var protocol = tls ? 'https://' : 'http://',
315319
path = baseDir ? '/' + baseDir.replace(/^\//, '') : '';
316320

doc/http-server.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ Connection timeout in seconds, e.g. -t60 for 1 minute.
106106
To disable timeout, use \-t0.
107107
Default is 120.
108108

109+
.TP
110+
.BI \-T ", " \-\-title " " \fITITLE\fR
111+
Custom title suffix for the terminal window.
112+
The terminal title will be "http-server PORT [TITLE]".
113+
109114
.TP
110115
.BI \-U ", " \-\-utc
111116
Use UTC time format in log messages.

0 commit comments

Comments
 (0)