Getting started
v0.1
Wiring: bootstrap/app.rs
use smeltery::AppBuilder;
use smeltery::middleware::{Next, Request};
use smeltery::Response;
#[derive(Clone)]
pub struct AppConfig {
pub name: String,
}
async fn log_requests(req: Request, next: Next) -> Response {
let path = req.uri().path().to_owned();
let res = next.run(req).await;
println!("{path} -> {}", res.status());
res
}
async fn home() -> &'static str { "home" }
pub fn build(app: AppBuilder) -> AppBuilder {
app.config(AppConfig { name: "Demo".into() })
.middleware("log", log_requests)
.routes(|r| {
r.get("/", home).name("home").middleware("log");
})
}
config(value)/service(value)register a value by type; handlers takeConfig<T>, other code callsapp.config::<T>()/app.service::<T>().middleware(alias, f)registers route middleware;global_middleware(f)runs on every request;middleware_family(prefix, make)registers aliases with arguments (see Routes and controllers).on_boot(|app| async move { … })runs async setup (open connections, register services) before the server starts.migrations(register),seeders(register)andcommands(register)take theregisterfunctions ofdatabase/migrations,database/seedersandapp/commands.auth::<User>()(one model per app: two different models stop the app at boot) makesUserthe modelAuthsigns in and registers thewebguard and theauth,guest,verifiedandpassword.confirmmiddleware;credential_listener(l),second_factor(f),login_completion(c)andlogin_policy(p)register the password-change hooks, a second factor, the sign-in completion and a rule every new sign-in meets;guard(g)registers another guard (see Guards and the principal).hallmark(Hallmark::new())(smeltery::hallmark::HallmarkExt) adds API tokens and theauth:hallmarkguard (see API tokens).bellows()(smeltery::bellows::BellowsExt) adds thebellows:mcpcommand (see Bellows below).