Tower Serve Static
Tower file services using include_dir and include_bytes to embed assets into the binary.
Usage
Cargo.toml
= { = "https://github.com/jannik4/tower-serve-static", = "0.1.0" }
= "0.7.0"
Serve Static File
use ;
// File is located relative to `CARGO_MANIFEST_DIR` (the directory containing the manifest of your package).
// This will embed and serve the `README.md` file.
let service = new;
// Run our service using `axum`
let app = new.nest_service;
// run our app with axum, listening locally on port 3000
let listener = bind.await?;
serve.await?;
Serve Static Directory
use ;
use ;
// Use `$CARGO_MANIFEST_DIR` to make path relative to your package.
// This will embed and serve files in the `src` directory and its subdirectories.
static ASSETS_DIR: = include_dir!;
let service = new;
// Run our service using `axum`
let app = new.nest_service;
// run our app with axum, listening locally on port 3000
let listener = bind.await?;
serve.await?;
Credits
The implementation is based on the tower-http file services (more specifically version 0.1.2) and adapted to use include_dir/include_bytes instead of the filesystem at runtime.