Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/avalon1610/spa-rs
Library who can embed all SPA web application files into a single binary executable.
https://github.com/avalon1610/spa-rs
Last synced: 3 months ago
JSON representation
Library who can embed all SPA web application files into a single binary executable.
- Host: GitHub
- URL: https://github.com/avalon1610/spa-rs
- Owner: avalon1610
- Created: 2022-06-16T14:35:40.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-06T13:36:52.000Z (9 months ago)
- Last Synced: 2024-07-16T14:38:11.061Z (4 months ago)
- Language: Rust
- Size: 73.2 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```rust
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
```rust
let forward_addr = "http://localhost:1234";
srv.reverse_proxy(forward_addr.parse()?);
```License: MIT