#static #file #server #http #cli

app sfz

A simple static file serving command-line tool

14 releases (7 breaking)

Uses new Rust 2021

0.7.0 Jan 20, 2022
0.6.2 Oct 10, 2021
0.6.1 Jul 10, 2021
0.4.0 Mar 18, 2021
0.0.3 Mar 7, 2018

#18 in HTTP server

Download history 75/week @ 2022-03-14 56/week @ 2022-03-21 15/week @ 2022-03-28 14/week @ 2022-04-04 8/week @ 2022-04-11 51/week @ 2022-04-18 50/week @ 2022-04-25 159/week @ 2022-05-02 21/week @ 2022-05-09 247/week @ 2022-05-16 88/week @ 2022-05-23 113/week @ 2022-05-30 100/week @ 2022-06-06 15/week @ 2022-06-13 23/week @ 2022-06-20 38/week @ 2022-06-27

204 downloads per month

MIT/Apache

135KB
2K SLoC

sfz

Crates.io Build Status Code Coverage Lines of Code Dependency Status

sfz, or Static File Zerver, is a simple command-line tool serving static files for you.

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

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:

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 via Cargo.

cargo install sfz

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

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

Manual

Prebuilt binaries

Archives of prebuilt binaries are available on GitHub 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.

Build from source

sfz is written in Rust. You need to install Rust in order to compile it.

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

Usage

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

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.

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, and sfz's directory-listing UI is mainly borrowed from GitHub.

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

License

This project is licensed under either of

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.

Dependencies

~18–26MB
~514K SLoC