Skip to main content

Module server

Module server 

Source
Expand description

Web server implementation for the Hammerwork dashboard.

This module provides the main WebDashboard struct for starting and configuring the web server, including database connections, authentication, and route setup.

§Examples

§Basic Server Setup

use hammerwork_web::{WebDashboard, DashboardConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = DashboardConfig::new()
        .with_bind_address("127.0.0.1", 8080)
        .with_database_url("postgresql://localhost/hammerwork");

    let dashboard = WebDashboard::new(config).await?;
    dashboard.start().await?;

    Ok(())
}

§Server with Authentication

use hammerwork_web::{WebDashboard, DashboardConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = DashboardConfig::new()
        .with_bind_address("0.0.0.0", 9090)
        .with_database_url("postgresql://localhost/hammerwork")
        .with_auth("admin", "$2b$12$hash...")
        .with_cors(true);

    let dashboard = WebDashboard::new(config).await?;
    dashboard.start().await?;

    Ok(())
}

Structs§

WebDashboard
Main web dashboard server.