product-os-server 0.0.55

Product OS : Server provides a full functioning advanced server capable of acting as a web server, command and control distributed network, authentication server, crawling server and more. Fully featured with high level of flexibility.
Documentation
//! HTTPS Server with TLS Example
//!
//! This example shows how to create an HTTPS server with TLS support.
//! The server will use self-signed certificates by default.

use product_os_server::{ProductOSServer, StatusCode, Response, Body};
use product_os_server::{ServerConfig, Certificate};
use product_os_async_executor::TokioExecutor;

async fn secure_handler() -> Result<Response<Body>, StatusCode> {
    Ok(Response::builder()
        .status(StatusCode::OK)
        .body(Body::from("This connection is secure!"))
        .unwrap())
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize tracing
    tracing_subscriber::fmt::init();

    // Create configuration with HTTPS enabled
    let mut config = ServerConfig::new();
    config.network.port = 8443;
    config.network.secure = true;
    config.network.host = "localhost".to_string();
    
    // Configure to use self-signed certificate
    config.certificate = Some(Certificate {
        file_kind: None, // Will generate self-signed
        files: None,
        entries: None,
        names: Some(vec!["localhost".to_string()]),
        serial: None,
        valid_for: None,
    });

    println!("Creating HTTPS server...");
    
    // Create server
    let mut server: ProductOSServer<(), TokioExecutor, _> = 
        ProductOSServer::new_with_config(config);

    // Add routes
    server.add_get("/secure", secure_handler);

    println!("HTTPS Server listening on https://localhost:8443");
    println!("Try:");
    println!("  curl -k https://localhost:8443/secure");
    println!("Note: -k flag is needed because this uses a self-signed certificate");

    // Start server
    server.start(false).await.map_err(|e| format!("Server error: {}", e))?;

    // Keep the main thread alive
    loop {
        tokio::time::sleep(std::time::Duration::from_secs(3600)).await;
    }
}