| Crates.io | anycms-spa |
| lib.rs | anycms-spa |
| version | 0.2.1 |
| created_at | 2025-08-08 20:55:27.03779+00 |
| updated_at | 2025-08-09 11:01:35.046795+00 |
| description | SPA intergration with Web Frameworks |
| homepage | https://anycms.org |
| repository | https://github.com/anycms/anycms-spa |
| max_upload_size | |
| id | 1787342 |
| size | 66,501 |
# actix-web 框架
anycms-spa = {version ="*",features = ["actix"]}
# axum 框架
anycms-spa = {version ="*",features = ["axum"]}
rust-embed = "8.7.2"
paste = "1.0.15"
spa! 宏使用宏需要用在 main.rs 或者 lib.rs 文件中
/// spa!(名称,资源路径, 路由前缀, [index文件名称数组])
/// 路由前缀和 index 文件名数组 可选
///spa!(name, assets_path, route_prefix, [index])
spa!(Spa, "assets");
/// 等价于
spa!(Spa, "assets", "/", ["index.html"]);
use actix_web::{App, HttpResponse, HttpServer, Responder, get, web};
use anycms_spa::spa;
use tracing::info;
// spa!(name,assets_path, route_prefix, index)]
spa!(Spa, "assets", "/", ["index.html"]);
spa!(Dashboard, "dashboard", "/dashboard", ["index.html"]);
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
info!("Hello, world!");
HttpServer::new(|| {
App::new()
.service(index)
.service(Dashboard::spa_service())
.service(Spa::spa_service())
})
.bind("127.0.0.1:8080")?
.run()
.await?;
Ok(())
}
#[get("/home")]
pub async fn index() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}