From 6ea1211bc5c0dc3f1bda948612cbbbe0985e0295 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Fri, 22 Feb 2019 10:50:14 -0800 Subject: [PATCH] It's alive! --- Cargo.lock | 2 ++ server/Cargo.toml | 2 ++ server/src/web/mod.rs | 45 ++++++++++++++++++++++++++++++------------- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0590b2da..108ee0c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1330,6 +1330,8 @@ dependencies = [ "csv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.12.23 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/server/Cargo.toml b/server/Cargo.toml index 84c8f653..344bc01e 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -20,6 +20,8 @@ clap = "2.27" csv = "1.0" env_logger = "0.6" failure = "0.1.3" +futures = "0.1" +hyper = "0.12" log = "0.4" maplit = "1.0.1" notify = "4.0" diff --git a/server/src/web/mod.rs b/server/src/web/mod.rs index e988b524..8e4e2978 100644 --- a/server/src/web/mod.rs +++ b/server/src/web/mod.rs @@ -5,8 +5,16 @@ mod interface; use std::sync::Arc; -use log::trace; -use rouille::{find_route, Request, Response}; +use futures::{ + future::{self, FutureResult}, + Future, +}; +use hyper::{ + service::Service, + Body, + Request, + Response, +}; use crate::{ live_session::LiveSession, @@ -22,6 +30,19 @@ pub struct Server { interface: interface::InterfaceServer, } +struct Blah; + +impl Service for Blah { + type ReqBody = Body; + type ResBody = Body; + type Error = hyper::Error; + type Future = Box, Error = Self::Error> + Send>; + + fn call(&mut self, request: Request) -> Self::Future { + Box::new(future::ok(Response::new(Body::from("Hello, world!")))) + } +} + impl Server { pub fn new(live_session: Arc) -> Server { Server { @@ -30,18 +51,16 @@ impl Server { } } - pub fn handle_request(&self, request: &Request) -> Response { - trace!("Request {} {}", request.method(), request.url()); - - find_route!( - self.api.handle_request(request), - self.interface.handle_request(request) - ) - } - pub fn listen(self, port: u16) { - let address = format!("0.0.0.0:{}", port); + let address = ([127, 0, 0, 1], port).into(); - rouille::start_server(address, move |request| self.handle_request(request)); + let server = hyper::Server::bind(&address) + .serve(move || { + let service: FutureResult = future::ok(Blah); + service + }) + .map_err(|e| eprintln!("Server error: {}", e)); + + hyper::rt::run(server); } } \ No newline at end of file