#web-apps #binary-executable #spa #web-dev #web-server #single

spa-rs

Embed all SPA web application files and release as a single binary executable

5 releases (3 breaking)

new 0.8.6 Mar 23, 2025
0.8.5 Mar 15, 2025
0.7.0 Feb 6, 2024
0.5.5 Mar 28, 2023
0.3.1 Jun 21, 2022

#476 in HTTP server

Download history 62/week @ 2025-03-09 65/week @ 2025-03-16

127 downloads per month

MIT license

70KB
1.5K SLoC

spa-rs

spa-rs is a library who can embed all SPA web application files (dist static file), and release as a single binary executable.

It based-on [axum] and [rust_embed]

It reexported all axum module for convenient use.

Example

use spa_rs::spa_server_root;
use spa_rs::SpaServer;
use spa_rs::routing::{get, Router};
use anyhow::Result;

spa_server_root!("web/dist");           // specific your SPA dist file location

#[tokio::main]
async fn main() -> Result<()> {
    let data = String::new();           // server context can be acccess by [axum::Extension]
    let mut srv = SpaServer::new()?
        .port(3000)
        .data(data)
        .static_path("/png", "web")     // static file generated in runtime
        .route("/api", Router::new()
            .route("/get", get(|| async { "get works" })
        )
    );
    srv.run(spa_server_root!()).await?;

    Ok(())
}

Session

See [session] module for more detail.

Dev

When writing SPA application, you may want use hot-reload functionallity provided by SPA framework. such as [vite dev] or [ng serve].

You can use spa-rs to reverse proxy all static requests to SPA framework. (need enable reverse-proxy feature)

Example

  let forward_addr = "http://localhost:1234";
  srv.reverse_proxy(forward_addr.parse()?);

License: MIT

Dependencies

~16–29MB
~510K SLoC