pub fn serve(
    repository: &Path,
    host: std::net::IpAddr,
    port: u16,
) -> Result<(), Error> {
    // Connect to database
    let db_path = repository.join("gitarchive.sqlite3");
    let db = Connection::open(db_path)?;
    let db = Arc::new(Mutex::new(db));
    let db = warp::any().map(move || db.clone());

    // Repository path
    let repo_path = Arc::new(repository.to_path_buf());
    let repo_path = warp::any().map(move || repo_path.clone());

    // Load templates
    let mut templates = Handlebars::new();
    #[cfg(debug_assertions)]
    templates.register_template_file("browse.html", "src/browse.html").unwrap();
    #[cfg(not(debug_assertions))]
    templates.register_template_string("browse.html", include_str!("browse.html")).unwrap();
    let templates = Arc::new(templates);
    let templates = warp::any().map(move || templates.clone());

    let routes =
        // Index, redirects to a branch in the latest snapshot
        path::end()
            .and(db.clone()).and_then(index)
        // Repo alone ("_"), same as index
        .or(path!("_").and(path::end())
            .and(db.clone()).and_then(index))
        // Snapshot without branch, redirect to a branch
        .or(path!("_" / String).and(path::end())
            .and(db.clone()).and_then(snapshot))
        // Browse view, shows a branch in a snapshot
        .or(path!("_" / String / String).and(path::end())
            .and(db).and(repo_path).and(templates).and_then(browse));

    println!("\n    Starting server on {}:{}\n", host, port);
    warp::serve(routes).run((host, port));

    Ok(())
}
/// Start the warp server with our routes
Start the warp server with our routes
Start the warp server with our routes
pub fn serve(
    repository: &Path,
    host: std::net::IpAddr,
    port: u16,
) -> Result<(), Error> {
    // Connect to database
    let db_path = repository.join("gitarchive.sqlite3");
    let db = Connection::open(db_path)?;
    let db = Arc::new(Mutex::new(db));
    let db = warp::any().map(move || db.clone());
    // Repository path
    let repo_path = Arc::new(repository.to_path_buf());
    let repo_path = warp::any().map(move || repo_path.clone());
    // Load templates
    let mut templates = Handlebars::new();
    #[cfg(debug_assertions)]
    templates.register_template_file("browse.html", "src/browse.html").unwrap();
    #[cfg(not(debug_assertions))]
    templates.register_template_string("browse.html", include_str!("browse.html")).unwrap();
    let templates = Arc::new(templates);
    let templates = warp::any().map(move || templates.clone());
    let routes =
        // Index, redirects to a branch in the latest snapshot
        path::end()
            .and(db.clone()).and_then(index)
        // Repo alone ("_"), same as index
        .or(path!("_").and(path::end())
            .and(db.clone()).and_then(index))
        // Snapshot without branch, redirect to a branch
        .or(path!("_" / String).and(path::end())
            .and(db.clone()).and_then(snapshot))
        // Browse view, shows a branch in a snapshot
        .or(path!("_" / String / String).and(path::end())
            .and(db).and(repo_path).and(templates).and_then(browse));
    println!("\n    Starting server on {}:{}\n", host, port);
    warp::serve(routes).run((host, port));
    Ok(())
}
pub fn serve ( repository : & Path , host : std :: net :: IpAddr , port : u16 , ) -> Result < ( ) , Error > { // Connect to database let db_path = repository . join ( " " ) ; let db = Connection :: open ( db_path ) ? ; let db = Arc :: new ( Mutex :: new ( db ) ) ; let db = warp :: any ( ) . map ( move | | db . clone ( ) ) ; // Repository path let repo_path = Arc :: new ( repository . to_path_buf ( ) ) ; let repo_path = warp :: any ( ) . map ( move | | repo_path . clone ( ) ) ; // Load templates let mut templates = Handlebars :: new ( ) ; # [ cfg ( debug_assertions ) ] templates . register_template_file ( " " , " " ) . unwrap ( ) ; # [ cfg ( not ( debug_assertions ) ) ] templates . register_template_string ( " " , include_str ! ( " " ) ) . unwrap ( ) ; let templates = Arc :: new ( templates ) ; let templates = warp :: any ( ) . map ( move | | templates . clone ( ) ) ; let routes = // Index, redirects to a branch in the latest snapshot path :: end ( ) . and ( db . clone ( ) ) . and_then ( index ) // Repo alone ("_"), same as index . or ( path ! ( " " ) . and ( path :: end ( ) ) . and ( db . clone ( ) ) . and_then ( index ) ) // Snapshot without branch, redirect to a branch . or ( path ! ( " " String ) . and ( path :: end ( ) ) . and ( db . clone ( ) ) . and_then ( snapshot ) ) // Browse view, shows a branch in a snapshot . or ( path ! ( " " String String ) . and ( path :: end ( ) ) . and ( db ) . and ( repo_path ) . and ( templates ) . and_then ( browse ) ) ; println ! ( " \n \n " host port ) ; warp :: serve ( routes ) . run ( ( host , port ) ) ; Ok ( ( ) ) }
Start the warp server with our routes
Start the warp server with our routes
repository
&Path
host
std::net::IpAddr
port
u16
repository
&Path
host
std::net::IpAddr
port
u16