📦 weihanglo / sfz

📄 README.md · 166 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166> Thank you for using this tool so far. Unfortunately I have no time
> maintaining it, but I believe people can find a better alternative
> out there on [crates.io](https://crates.io).
>
> If you are still interested in supporting Rust and its community, please
> consider **sponsoring Rust developers you like**. You can find a few from
> the official [Rust teams](https://www.rust-lang.org/governance/),
> or just [buy me a coffee](https://github.com/sponsors/weihanglo) ❤️.

# [![sfz](.github/sfz.svg)][sfz]

[![Crates.io](https://img.shields.io/crates/v/sfz.svg)](https://crates.io/crates/sfz)
[![Build Status](https://github.com/weihanglo/sfz/workflows/CI/badge.svg)](https://github.com/weihanglo/sfz/actions?query=workflow%3ACI)
[![Code Coverage](https://codecov.io/gh/weihanglo/sfz/coverage.svg)](https://codecov.io/gh/weihanglo/sfz)
[![Lines of Code](https://tokei.rs/b1/github/weihanglo/sfz?category=code)][sfz]
[![Dependency Status](https://deps.rs/repo/github/weihanglo/sfz/status.svg)](https://deps.rs/repo/github/weihanglo/sfz)

sfz, or **S**tatic **F**ile **Z**erver, is a simple command-line tool serving static files for you.

![](.github/cover.png)

The name **sfz** is derived from an accented note [Sforzando][sforzando] in music, which means “suddenly with force.”

[sfz]: https://github.com/weihanglo/sfz
[sforzando]: https://en.wikipedia.org/wiki/Dynamics_(music)#Sudden_changes_and_accented_notes

## Features

- Directory listing
- Partial responses (range requests)
- Conditional requests with cache validations
- Cross-origin resource sharing
- Automatic HTTP compression (Brotli, Gzip, Deflate)
- Automatic rendering `index.html`
- Respect `.gitignore` file
- Customize path prefix

## Installation

### Automatic

#### macOS

If you are a **macOS Homebrew** user, you can install sfz from a custom tap:

```shell
brew tap weihanglo/sfz https://github.com/weihanglo/sfz.git
brew install sfz
```

> Disclaimer: Formula on **Linuxbrew** did not fully tested.

#### Cargo

If you are a **Rust programmer**, sfz are available on [crates.io][crates.io] via [Cargo][cargo].

```shell
cargo install sfz
```

You can also install the latest version (or a specific commit) of sfz directly from GitHub.

```shell
cargo install --git https://github.com/weihanglo/sfz.git
```

[crates.io]: https://crates.io
[cargo]: https://doc.rust-lang.org/cargo/

### Manual

#### Prebuilt binaries

Archives of prebuilt binaries are available on [GitHub Release][gh-release] for Linux, maxOS and Windows. Download a compatible binary for your system. For convenience, make sure you place sfz under $PATH if you want access it from the command line.

[gh-release]: https://github.com/weihanglo/sfz/releases

#### Build from source

sfz is written in Rust. You need to [install Rust][install-rust] in order to compile it.

```shell
$ git clone https://github.com/weihanglo/sfz.git
$ cd sfz
$ cargo build --release
$ ./target/release/sfz --version
0.7.1
```

[install-rust]: https://www.rust-lang.org/install.html

## Usage

The simplest way to start serving files is to run this command:

```shell
sfz [FLAGS] [OPTIONS] [path]
```

The command above will start serving your current working directory on `127.0.0.1:5000` by default.

If you want to serve another directory, pass `[path]` positional argument in with either absolute or relaitve path.

```shell
sfz /usr/local

# Serve files under `/usr/local` directory.
# 
# You can press ctrl-c to exit immediately.
```

### Flags and Options

sfz aims to be simple but configurable. Here is a list of available options:

```
USAGE:
    sfz [OPTIONS] [path]

ARGS:
    <path>    Path to a directory for serving files [default: .]

OPTIONS:
    -a, --all                   Serve hidden and dot (.) files
    -b, --bind <address>        Specify bind address [default: 127.0.0.1]
    -c, --cache <seconds>       Specify max-age of HTTP caching in seconds [default: 0]
    -C, --cors                  Enable Cross-Origin Resource Sharing from any origin (*)
        --coi                   Enable Cross-Origin isolation
    -h, --help                  Print help information
    -I, --no-ignore             Don't respect gitignore file
    -L, --follow-links          Follow symlinks outside current serving base path
        --no-log                Don't log any request/response information.
    -p, --port <port>           Specify port to listen on [default: 5000]
        --path-prefix <path>    Specify an url path prefix, helpful when running behing a reverse
                                proxy
    -r, --render-index          Render existing index.html when requesting a directory.
    -V, --version               Print version information
    -Z, --unzipped              Disable HTTP compression
```

## Contributing

Contributions are highly appreciated! Feel free to open issues or send pull requests directly.

## Credits

sfz was originally inspired by another static serving tool [serve][serve], and sfz's directory-listing UI is mainly borrowed from [GitHub][github].

sfz is built on the top of awesome Rust community. Thanks for all Rust and crates contributors.

[serve]: https://github.com/zeit/serve
[github]: https://github.com/

## License

This project is licensed under either of

- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in sfz by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.