#tide #static #files

tide-naive-static-files

A simple static file serving component for Rust’s Tide web framework

7 releases (stable)

✓ Uses Rust 2018 edition

2.2.0 Feb 28, 2020
2.1.0 Jan 2, 2020
2.0.2 Dec 21, 2019
1.0.0 Dec 2, 2019
0.1.0 Nov 30, 2019

#103 in HTTP server

Download history 10/week @ 2020-03-14 36/week @ 2020-03-21 57/week @ 2020-03-28 36/week @ 2020-04-04 58/week @ 2020-04-11 17/week @ 2020-04-18 4/week @ 2020-04-25 3/week @ 2020-05-02 2/week @ 2020-05-09 26/week @ 2020-05-16 8/week @ 2020-05-23 18/week @ 2020-05-30 10/week @ 2020-06-06 15/week @ 2020-06-13 2/week @ 2020-06-20 8/week @ 2020-06-27

122 downloads per month
Used in cargo-gui

MIT/Apache and maybe MPL-2.0

16KB
95 lines

tide-naive-static-files

A simple static file serving component for Rust's Tide web framework.

Acknowledgements

This code is based heavily on this archived example.

This crate is not officially associated with the tide project, it's more of an interim solution while tide is still in a state of (relative) flux.

Note on Version Numbers

Mistakes were made when initially selecting version numbers for this crate. In the Rust ecosystem, a 1.0.0 release generally means the crate is fit for production. This crate makes no such claim. It would be best to "divide by ten" when looking at the crate's version number (i.e. 2.0.1 should be thought of as 0.2.0.1).

Example

To use the library:

  1. Define the route to host your assets under
  2. Stip the prefix so the routes match your files
  3. Set up a get endpoint with the StaticFilesEndpoint making sure the root represents the path from where you run the server to the root of your assets
use async_std::task;
use tide_naive_static_files::StaticFilesEndpoint;

struct AppState {}

fn main() {
    let state = AppState {};

    let mut app = tide::with_state(state);
    app.at("/static") // 1.
       .strip_prefix() // 2
       .get(StaticFilesEndpoint {
        root: "./examples/".into(), // 3.
    });

    task::block_on(async move { app.listen("127.0.0.1:8000").await.unwrap() });
}

Contributors

If you're interested in contributing to the project, please see our CONTRIBUTING.md file!

Dependencies

~6–8.5MB
~177K SLoC