pub fn serve<E: SemanticEngine + 'static>(config: &Config, engine: E) -> Result<Server> {
    use persistent::{Read, Write};
    use logger::Logger;

    let mut chain = Chain::new(router!(
        post "/parse_file"       => file::parse,
        post "/find_definition"  => definition::find,
        post "/list_completions" => completion::list,
        get  "/ping"             => ping::pong));

    // Logging middleware
    let (log_before, log_after) = Logger::new(None);

    // log_before must be first middleware in before chain
    if config.print_http_logs {
        chain.link_before(log_before);
    }

    // Get HMAC Middleware
    let (hmac_before, hmac_after) = if config.secret_file.is_some() {
        let secret = config.read_secret_file();
        let hmac_header = "x-racerd-hmac";
        let (before, after) = Hmac256Authentication::middleware(secret, hmac_header);
        (Some(before), Some(after))
    } else {
        (None, None)
    };

    // This middleware provides a semantic engine to the request handlers
    chain.link_before(Write::<EngineProvider>::one(Box::new(engine)));

    // Body parser middlerware
    chain.link_before(Read::<::bodyparser::MaxBodyLength>::one(1024 * 1024 * 10));

    // Maybe link hmac middleware
    if let Some(hmac) = hmac_before {
        chain.link_before(hmac);
    }

    if let Some(hmac) = hmac_after {
        chain.link_after(hmac);
    }


    // log_after must be last middleware in after chain
    if config.print_http_logs {
        chain.link_after(log_after);
    }

    let app = Iron::new(chain);

    Ok(Server {
        inner: try!(app.http((&config.addr[..], config.port)))
    })
}
/// Start the http server using the given configuration
///
/// `serve` is non-blocking.
///
/// # Example
///
/// ```no_run
/// # use libracerd::{Config};
/// let mut cfg = Config::new();
/// cfg.port = 3000;
///
/// let engine = ::libracerd::engine::Racer::new();
///
/// let mut server = ::libracerd::http::serve(&cfg, engine).unwrap();
/// // ... later
/// server.close().unwrap();
/// ```
///
Start the http server using the given configuration
`serve` is non-blocking.
Start the http server using the given configuration ` serve ` is non - blocking .
pub fn serve<E: SemanticEngine + 'static>(config: &Config, engine: E) -> Result<Server> {
    use persistent::{Read, Write};
    use logger::Logger;
    let mut chain = Chain::new(router!(
        post "/parse_file"       => file::parse,
        post "/find_definition"  => definition::find,
        post "/list_completions" => completion::list,
        get  "/ping"             => ping::pong));
    // Logging middleware
    let (log_before, log_after) = Logger::new(None);
    // log_before must be first middleware in before chain
    if config.print_http_logs {
        chain.link_before(log_before);
    }
    // Get HMAC Middleware
    let (hmac_before, hmac_after) = if config.secret_file.is_some() {
        let secret = config.read_secret_file();
        let hmac_header = "x-racerd-hmac";
        let (before, after) = Hmac256Authentication::middleware(secret, hmac_header);
        (Some(before), Some(after))
    } else {
        (None, None)
    };
    // This middleware provides a semantic engine to the request handlers
    chain.link_before(Write::<EngineProvider>::one(Box::new(engine)));
    // Body parser middlerware
    chain.link_before(Read::<::bodyparser::MaxBodyLength>::one(1024 * 1024 * 10));
    // Maybe link hmac middleware
    if let Some(hmac) = hmac_before {
        chain.link_before(hmac);
    }
    if let Some(hmac) = hmac_after {
        chain.link_after(hmac);
    }
    // log_after must be last middleware in after chain
    if config.print_http_logs {
        chain.link_after(log_after);
    }
    let app = Iron::new(chain);
    Ok(Server {
        inner: try!(app.http((&config.addr[..], config.port)))
    })
}
pub fn serve < E : SemanticEngine + ' static > ( config : & Config , engine : E ) -> Result < Server > { use persistent :: { Read , Write } ; use logger :: Logger ; let mut chain = Chain :: new ( router ! ( post " " file parse post " " definition find post " " completion list get " " ping pong ) ) ; // Logging middleware let ( log_before , log_after ) = Logger :: new ( None ) ; // log_before must be first middleware in before chain if config . print_http_logs { chain . link_before ( log_before ) ; } // Get HMAC Middleware let ( hmac_before , hmac_after ) = if config . secret_file . is_some ( ) { let secret = config . read_secret_file ( ) ; let hmac_header = " " ; let ( before , after ) = Hmac256Authentication :: middleware ( secret , hmac_header ) ; ( Some ( before ) , Some ( after ) ) } else { ( None , None ) } ; // This middleware provides a semantic engine to the request handlers chain . link_before ( Write :: < EngineProvider > :: one ( Box :: new ( engine ) ) ) ; // Body parser middlerware chain . link_before ( Read :: < :: bodyparser :: MaxBodyLength > :: one ( 1024 * 1024 * 10 ) ) ; // Maybe link hmac middleware if let Some ( hmac ) = hmac_before { chain . link_before ( hmac ) ; } if let Some ( hmac ) = hmac_after { chain . link_after ( hmac ) ; } // log_after must be last middleware in after chain if config . print_http_logs { chain . link_after ( log_after ) ; } let app = Iron :: new ( chain ) ; Ok ( Server { inner : try ! ( app http ( ( config addr [ ] config port ) ) ) } ) }
Start the http server using the given configuration
`serve` is non-blocking.
Start the http server using the given configuration ` serve ` is non - blocking .
config
&Config
engine
E
config
&Config
engine
E
example
None
use libracerd::{config};
let mut cfg = Config::new();
cfg.port = 3000.

let engine = ::libracerd::engine::Racer::new().

let mut server = ::libracerd::http::serve(&cfg, engine).unwrap();
later
server.close().unwrap();
```
let mut cfg = Config :: new () ; cfg . port = 3000 . let engine = :: libracerd :: engine :: Racer :: new () . let mut server = :: libracerd :: http :: serve ( &cfg engine ) . unwrap () ; later server . close () . unwrap () ; ` ` `