Examples
Simple Static Server
use lithair_core::app::LithairServer;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
LithairServer::new()
.with_port(3007)
.with_frontend_at("/", "./public")
.serve()
.await
}
REST API with Data Model
use lithair_core::app::LithairServer;
use lithair_core::DeclarativeModel;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, DeclarativeModel)]
struct Task {
#[http(expose)]
id: String,
#[http(expose, validate = "non_empty")]
title: String,
#[http(expose)]
completed: bool,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
LithairServer::new()
.with_port(3007)
.with_model::<Task>("./data/tasks", "/api/tasks")
.with_frontend_at("/", "./public")
.serve()
.await
}
Full-Stack with Auth + MFA
use lithair_core::app::LithairServer;
use lithair_core::mfa::MfaConfig;
use lithair_core::rbac::{RbacUser, ServerRbacConfig};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let rbac = ServerRbacConfig {
roles: vec![("Admin".to_string(), vec!["*".to_string()])],
users: vec![RbacUser::new("admin", "changeme", "Admin")],
session_store_path: Some("./data/sessions".to_string()),
session_duration: 28800,
};
LithairServer::new()
.with_port(3007)
.with_frontend_at("/", "./public")
.with_rbac_config(rbac)
.with_mfa_totp(MfaConfig {
issuer: "My App".to_string(),
enforce_for_roles: vec!["Admin".to_string()],
..Default::default()
})
.serve()
.await
}