Skip to content

Commit

Permalink
refactor!: update cli options to use --no prefix for boolean values (#46
Browse files Browse the repository at this point in the history
)

BREAKING CHANGES:

1. --dir-list renamed to --dirlist
2. --dir-file renamed to --dirfile
3. The previously supported text syntax for boolean arguments,
using text values (e.g. '--cors=true' or '--gzip false'), is not supported
after this change. Instead, '--cors' (true) and '--no-cors' (false)
or '--gzip' (true) and '--no-gzip' (false) should be used.
  • Loading branch information
fvsch authored Nov 27, 2024
1 parent 5565d68 commit ecf82d1
Show file tree
Hide file tree
Showing 11 changed files with 636 additions and 452 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You can configure servitsy's behavior [with options](https://github.com/fvsch/se
npx servitsy -p 3000 --cors

# Serve 'dist' folder and disable directory listings
npx servitsy dist --dir-list false
npx servitsy dist --no-dirlist
```

- Use `npx servitsy --help` for an overview of available options.
Expand Down
62 changes: 37 additions & 25 deletions doc/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
servitsy supports the following command-line options:

- [`--cors`](#cors): send CORS HTTP headers in responses
- [`--dir-file`](#dirfile): directory index file(s)
- [`--dir-list`](#dirlist): allow listing directory contents
- [`--dirfile`](#dirfile): directory index file(s)
- [`--dirlist`](#dirlist): allow listing directory contents
- [`--exclude`](#exclude)
- [`--ext`](#ext): extensions which can be omitted in URLs
- [`--gzip`](#gzip): use gzip compression for text files
Expand All @@ -24,19 +24,25 @@ Currently, setting this option to `true` will add a `Access-Control-Allow-Origin
```sh
# Enable
servitsy --cors
servitsy --cors true

# Disable (default)
servitsy --cors false
servitsy --no-cors
```

## `dirFile`

File names to look up when a request matches a directory. Defaults to `index.html`.

```sh
servitsy --dir-file 'index.html'
servitsy --dir-file 'page.html,page.htm'
# Default value
servitsy --dirfile 'index.html'

# Custom values
servitsy --dirfile 'index.html,index.htm' --dirfile 'page.html,page.htm'

# Disable defaults
servitsy --dirfile ''
servitsy --no-dirfile
```

## `dirList`
Expand All @@ -45,27 +51,28 @@ Whether to list directory contents when a request matches a directory and no `di

```sh
# Enable (default)
servitsy --dir-list
servitsy --dir-list true
servitsy --dirlist

# Disable
servitsy --dir-list false
servitsy --no-dirlist
```

## `exclude`

Block access to files and folders matched by the provided pattern(s). Patterns may use the wildcard character `*`, but not slashes or colons (`/`, `\` or `:`). Use a pattern starting with `!` to negate an exclusion rule.
Blocks access to files and folders matched by the provided pattern(s). Patterns may use the wildcard character `*`, but not slashes or colons (`/`, `\` or `:`). Use a pattern starting with `!` to negate an exclusion rule.

Defaults to blocking all dotfiles, except for `.well-known` (see [Well-known URI](https://en.wikipedia.org/wiki/Well-known_URI)):
Defaults to blocking all dotfiles, except for `.well-known` (see [Well-known URI](https://en.wikipedia.org/wiki/Well-known_URI)). Note that specifying any `exclude` value will override the defaults, so make sure to include a rule such as `--exclude '.*'` if you want to block dotfiles.

```sh
servitsy --exclude '.*' --exclude '!.well-known'
```
# Default value
servitsy --exclude '.*,!.well-known'

Patterns can also be provided as comma-separated values:
# Custom values
servitsy --exclude '.*' --exclude '_*' --exclude '*.yml,*.yaml'

```sh
servitsy --exclude '.*,!.well-known'
# Disable default value
servitsy --exclude ''
servitsy --no-exclude
```

Blocked requests will result in a 404 error. Requests will be blocked if any file or folder name in the requested path matches an exclusion rule (and does not also match a negative exclusion rule).
Expand All @@ -83,9 +90,15 @@ File extensions to look for when resolving a request. Defaults to `.html`.
Typically, this allows serving a `<root_dir>/page-name.html` file for a request URL path of `/page-name`.

```sh
servitsy --ext '' # disable
servitsy --ext '.html' # default
# Default value
servitsy --ext '.html'

# Custom values
servitsy --ext '.xhtml' --ext '.html'

# Disable defaults
servitsy --ext ''
servitsy --no-ext
```

## `gzip`
Expand All @@ -95,15 +108,14 @@ Enables gzip compression for text files. Defaults to `true`.
```sh
# Enable (default)
servitsy --gzip
servitsy --gzip true

# Disable
servitsy --gzip false
servitsy --no-gzip
```

## `header`

Add custom HTTP headers to responses, for all files or specific file patterns. Headers can be provided using a `header:value` syntax, or as a JSON string:
Adds custom HTTP headers to responses, for all files or specific file patterns. Headers can be provided using a `header:value` syntax, or as a JSON string:

```sh
# header:value syntax
Expand All @@ -127,7 +139,7 @@ See the [`exclude` option](#exclude) for more information about file matching pa

## `host`

Host address that the server will listen on. May be a domain name or an IP address.
The host address that the server will listen on. May be a domain name or an IP address.

Defaults to `0.0.0.0`, which means that the server will be available both on `http://localhost:<port>/` and from other computers connected to the same network.

Expand All @@ -138,7 +150,9 @@ servitsy --host mysite.local

## `port`

Port number to use for the server. Three formats are supported:
The port number to use for the server, and optionally the numbers to try as fallback if the first port is busy. Defaults to `8080+`.

Three formats are supported:

```sh
servitsy --port 3000
Expand All @@ -149,5 +163,3 @@ servitsy --port 8080-8099
- `<number>`: specify a single port number, will error out if that port is busy;
- `<number>+`: specifies the first port number to try, and allow trying the next few port numbers if the first one is busy;
- `<number>-<number>`: a range of port numbers to try (from first to last).

Defaults to `8080+`.
Loading

0 comments on commit ecf82d1

Please sign in to comment.