Skip to main content

Crate sppl

Crate sppl 

Source
Expand description

sppl — embed static Svelte (and other static) apps into Rust servers.

#[derive(sppl::RustEmbed)]
#[folder = "$CARGO_MANIFEST_DIR/../app/build"]
#[crate_path = "sppl::rust_embed"]
struct App;

#[tokio::main]
async fn main() {
    let app = sppl::axum::router::<App>();
    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
}

§Compression

sppl understands a directory in which compressible files have been pre-gzipped (e.g. index.htmlindex.html.gz). Use build::gzip_assets from your build.rs to do it once at compile time; at request time sppl::resolve prefers the .gz variant if present.

By default the axum router sends the stored gzipped bytes to every client with Content-Encoding: gzip, regardless of Accept-Encoding. Modern clients decompress transparently and you cap the per-request CPU cost at zero. Flip axum::RouterConfig::never_decompress to false to restore on-the-fly decompression via flate2 for clients that truly can’t accept gzip.

Modules§

axum
Axum integration.
build
Helpers intended to be called from a downstream build.rs.

Structs§

Asset
A resolved embedded asset, after applying SvelteKit adapter-static and SPA-fallback lookup rules and after picking a .gz variant if available.
EmbeddedFile
A file embedded into the binary

Traits§

RustEmbed
A directory of binary assets.

Functions§

resolve
Look up a file in an embedded asset bundle, applying the resolution rules that match SvelteKit’s adapter-static output, with a .gz fast-path:

Derive Macros§

RustEmbed