Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for base dir (-b --baseDir) #481

Closed
wants to merge 2 commits into from
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ This will install `http-server` globally so that it may be run from the command

`-o` Open browser window after starting the server

`-b` or `--baseDir` If -o is used then open given base dir. e.g.: `hs -o -b docs` => http://127.0.0.1:8080/docs

`-c` Set cache time (in seconds) for cache-control max-age header, e.g. `-c10` for 10 seconds (defaults to `3600`). To disable caching, use `-c-1`.

`-U` or `--utc` Use UTC time format in log messages.
Expand Down
5 changes: 3 additions & 2 deletions bin/http-server
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ if (argv.h || argv.help) {
' -s --silent Suppress log messages from output',
' --cors[=headers] Enable CORS via the "Access-Control-Allow-Origin" header',
' Optionally provide CORS headers list separated by commas',
' -o [path] Open browser window after starting the server',
' -o [cmd] Open browser window after starting the server',
' -b --baseDir If -o then open that base dir. e.g.: docs => http://127.0.0.1:8080/docs',
' -c Cache time (max-age) in seconds [3600], e.g. -c10 for 10 seconds.',
' To disable caching, use -c-1.',
' -U --utc Use UTC time format in log messages.',
Expand Down Expand Up @@ -151,7 +152,7 @@ function listen(port) {
logger.info('Hit CTRL-C to stop the server');
if (argv.o) {
opener(
protocol + canonicalHost + ':' + port,
protocol + canonicalHost + ':' + port + (argv.b ? '/' + argv.b : ''),
{ command: argv.o !== true ? argv.o : null }
);
}
Expand Down