Skip to main content

handle_server

Function handle_server 

Source
pub fn handle_server(
    log_file: &mut File,
    date: &str,
    paths: &Paths,
    serve_dir: &PathBuf,
) -> Result<()>
Expand description

Configures and launches the development server.

Sets up a local server for testing and previewing the generated site. Handles file copying and server configuration for local development.

§Arguments

  • log_file - Reference to the active log file
  • date - Current timestamp for logging
  • paths - All required directory paths
  • serve_dir - Directory to serve content from

§Returns

  • Ok(()) - If server starts successfully
  • Err - If server configuration or startup fails

§Examples

use std::path::PathBuf;
use ssg::{Paths, handle_server, create_log_file};

fn main() -> anyhow::Result<()> {
    let mut log_file = create_log_file("./server.log")?;
    let date = ssg::now_iso();
    let paths = Paths {
        site: PathBuf::from("public"),
        content: PathBuf::from("content"),
        build: PathBuf::from("build"),
        template: PathBuf::from("templates"),
    };
    let serve_dir = PathBuf::from("serve");

    handle_server(&mut log_file, &date, &paths, &serve_dir)?;
    Ok(())
}

§Server Configuration

  • Default port: 8000
  • Host: 127.0.0.1 (localhost)
  • Serves static files from the specified directory