Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ This will install `http-server` globally so that it may be run from the command
|`-r` or `--robots` | Automatically provide a /robots.txt (The content of which defaults to `User-agent: *\nDisallow: /`) | `false` |
|`--no-dotfiles` |Do not show dotfiles| |
|`--mimetypes` |Path to a .types file for custom mimetype definition| |
|`-H` or `--headers` |Semi-colon separated list of headers to use (Ex.: `Cross-Origin-Resource-Policy:same-site;Cross-Origin-Opener-Policy:same-origin`)| |
|`-h` or `--help` |Print this list and exit. | |
|`-v` or `--version`|Print the version and exit. | |

Expand Down
9 changes: 9 additions & 0 deletions bin/http-server
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ if (argv.h || argv.help) {
' -r --robots Respond to /robots.txt [User-agent: *\\nDisallow: /]',
' --no-dotfiles Do not show dotfiles',
' --mimetypes Path to a .types file for custom mimetype definition',
' -H --headers Semi-colon separated list of headers to use',
' -h --help Print this list and exit.',
' -v --version Print the version and exit.'
].join('\n'));
Expand Down Expand Up @@ -156,6 +157,13 @@ function listen(port) {
password: argv.password || process.env.NODE_HTTP_SERVER_PASSWORD
};

if (argv.H || argv.headers) {
options.headers = {};
for (let h of (argv.H || argv.headers).split(/\s*;\s*/).map((x) => {x = x.split(/\s*:\s*/); x.push(''); return x.slice(0, 2);})) {
options.headers[h[0]] = h[1];
}
}

if (argv.cors) {
options.cors = true;
if (typeof argv.cors === 'string') {
Expand Down Expand Up @@ -211,6 +219,7 @@ function listen(port) {
chalk.yellow('\nhttp-server settings: '),
([chalk.yellow('CORS: '), argv.cors ? chalk.cyan(argv.cors) : chalk.red('disabled')].join('')),
([chalk.yellow('Cache: '), argv.c ? (argv.c === '-1' ? chalk.red('disabled') : chalk.cyan(argv.c + ' seconds')) : chalk.cyan('3600 seconds')].join('')),
([chalk.yellow('Headers: ', argv.H || argv.headers ? chalk.cyan(argv.H || argv.headers) : chalk.red('none'))]),
([chalk.yellow('Connection Timeout: '), argv.t === '0' ? chalk.red('disabled') : (argv.t ? chalk.cyan(argv.t + ' seconds') : chalk.cyan('120 seconds'))].join('')),
([chalk.yellow('Directory Listings: '), argv.d ? chalk.red('not visible') : chalk.cyan('visible')].join('')),
([chalk.yellow('AutoIndex: '), argv.i ? chalk.red('not visible') : chalk.cyan('visible')].join('')),
Expand Down
4 changes: 4 additions & 0 deletions doc/http-server.1
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ If not specified, uses "User-agent: *\\nDisallow: /]"
.BI \-\-no\-dotfiles
Do not show dotfiles.

.TP
.BI \-H ", " \-\-headers " " [\fIHEADERS\fR]
Semi-colon separated list of custom headers.

.TP
.BI \-h ", " \-\-help
Print usage and exit.
Expand Down