feat(api): add Leptos server functions bridging client and server
- Add src/api/ module with server functions for networks, hosts, applications - Each server function retrieves the pool via use_context::<AnyPool>() - Pool is injected via provide_context in two places in main.rs: * leptos_routes_with_context: for SSR renders and inline server fn calls * handle_server_fns_with_context on /api/*fn_name: for WASM client calls - create_host validates IP against network CIDR before inserting - create_network validates CIDR format before inserting Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
19
src/api/mod.rs
Normal file
19
src/api/mod.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
// api/ — Leptos server functions (the bridge between client and server)
|
||||
//
|
||||
// Server functions are annotated with `#[server]`.
|
||||
// Leptos compiles them differently depending on the active feature:
|
||||
//
|
||||
// ssr → the function body runs on the server (normal async Rust code)
|
||||
// hydrate → the body is replaced by an HTTP POST call to /api/<fn-name>
|
||||
//
|
||||
// This means:
|
||||
// - Function signatures (arguments + return types) must compile for BOTH targets.
|
||||
// All types used here must also be in `models.rs` (shared code).
|
||||
// - Imports inside the function body are only compiled for `ssr`,
|
||||
// so ssr-only modules (server::repository, sqlx) can be used freely there.
|
||||
// - The pool is retrieved via `use_context::<AnyPool>()` — it is injected
|
||||
// into the Leptos context by `main.rs` for every request.
|
||||
|
||||
pub mod applications;
|
||||
pub mod hosts;
|
||||
pub mod networks;
|
||||
Reference in New Issue
Block a user