pub fn listen<A>(addr: A, database_uri: &str) -> Result<Listening>
where
    A: ToSocketAddrs,
{
    let config_path = env::var("WEBSITE_CONFIG").unwrap_or_else(|_| String::from("config.yaml"));
    let config = config::load(config_path).chain_err(|| "could not parse configuration")?;
    let projects = projects::load("projects.yaml").chain_err(|| "problem parsing projects")?;

    // Insert blog posts into the database.
    let pool = persistence::get_connection_pool(database_uri)?;
    let connection = pool.get().chain_err(|| "database connection timed out")?;

    let schema = {
        let mut schema_file = File::open("schema.sql")?;
        let mut schema = String::new();
        schema_file.read_to_string(&mut schema)?;
        schema
    };
    connection.batch_execute(&schema).unwrap();

    blog::load("blog/", &connection).chain_err(|| "problem parsing blog posts")?;

    let handler = routes::handler(config, projects, pool)?;

    info!("initialization complete");

    let listening = Iron::new(handler).http(addr)?;
    info!("listening on {}", listening.socket);

    Ok(listening)
}
/// Starts the server listening on the provided socket address.
Starts the server listening on the provided socket address.
Starts the server listening on the provided socket address .
pub fn listen<A>(addr: A, database_uri: &str) -> Result<Listening>
where
    A: ToSocketAddrs,
{
    let config_path = env::var("WEBSITE_CONFIG").unwrap_or_else(|_| String::from("config.yaml"));
    let config = config::load(config_path).chain_err(|| "could not parse configuration")?;
    let projects = projects::load("projects.yaml").chain_err(|| "problem parsing projects")?;
    // Insert blog posts into the database.
    let pool = persistence::get_connection_pool(database_uri)?;
    let connection = pool.get().chain_err(|| "database connection timed out")?;
    let schema = {
        let mut schema_file = File::open("schema.sql")?;
        let mut schema = String::new();
        schema_file.read_to_string(&mut schema)?;
        schema
    };
    connection.batch_execute(&schema).unwrap();
    blog::load("blog/", &connection).chain_err(|| "problem parsing blog posts")?;
    let handler = routes::handler(config, projects, pool)?;
    info!("initialization complete");
    let listening = Iron::new(handler).http(addr)?;
    info!("listening on {}", listening.socket);
    Ok(listening)
}
pub fn listen < A > ( addr : A , database_uri : & str ) -> Result < Listening > where A : ToSocketAddrs , { let config_path = env :: var ( " " ) . unwrap_or_else ( | _ | String :: from ( " " ) ) ; let config = config :: load ( config_path ) . chain_err ( | | " " ) ? ; let projects = projects :: load ( " " ) . chain_err ( | | " " ) ? ; // Insert blog posts into the database. let pool = persistence :: get_connection_pool ( database_uri ) ? ; let connection = pool . get ( ) . chain_err ( | | " " ) ? ; let schema = { let mut schema_file = File :: open ( " " ) ? ; let mut schema = String :: new ( ) ; schema_file . read_to_string ( & mut schema ) ? ; schema } ; connection . batch_execute ( & schema ) . unwrap ( ) ; blog :: load ( " " , & connection ) . chain_err ( | | " " ) ? ; let handler = routes :: handler ( config , projects , pool ) ? ; info ! ( " " ) ; let listening = Iron :: new ( handler ) . http ( addr ) ? ; info ! ( " " listening socket ) ; Ok ( listening ) }
Starts the server listening on the provided socket address.
Starts the server listening on the provided socket address .
addr
A
database_uri
&str
addr
A
database_uri
&str