lib.rs 43 lignes · 1605 octets
//! Rustwarden UI
//!
//! Default HTML user interface for the Rustwarden framework.
//! Provides login pages, profile management, admin panel, and all associated routes.

/// Template context for the audience-measurement opt-out component.
pub mod analytics;
/// Data Transfer Objects for request/response handling.
pub mod dto;
/// Custom Axum extractors (e.g. form with duplicate fields).
pub mod extractors;
/// HTTP request handlers (login, admin, settings, etc.).
pub mod handlers;
/// Route definitions and router construction.
pub mod routes;
/// Shared Askama template helpers and base context.
pub mod template_helpers;

use axum::Router;
use sea_orm::DatabaseConnection;
use tower_http::services::ServeDir;

pub use routes::{api_routes, browser_routes};

/// Returns the default UI routes for Rustwarden (login, profile, admin, etc.).
///
/// This combines the browser SSR routes and the `/api/v1/*` machine API in a
/// single router. Because mounting it via `with_ui` would put `/api/v1/*`
/// behind the CSRF layer, prefer mounting [`browser_routes`] via `with_ui`
/// and [`api_routes`] via `merge_machine_routes` instead.
#[deprecated(
    note = "Mount browser_routes() via with_ui() and api_routes() via merge_machine_routes(); see CSRF plan"
)]
pub fn default_routes() -> Router<DatabaseConnection> {
    routes::create_router()
}

/// Returns a static file service for serving CSS, JS, and images.
pub fn default_static_service() -> ServeDir {
    let static_dir =
        std::env::var("RUSTWARDEN_STATIC_DIR").unwrap_or_else(|_| "static".to_string());
    ServeDir::new(static_dir)
}