diff --git a/Cargo.lock b/Cargo.lock index af361da49..feda5db77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -321,6 +321,7 @@ dependencies = [ "jsonrpc-core 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 4.0.0 (git+https://github.com/tomusdrw/jsonrpc-http-server.git)", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-status 0.1.1 (git+https://github.com/tomusdrw/parity-status.git)", "parity-wallet 0.1.0 (git+https://github.com/tomusdrw/parity-wallet.git)", "parity-webapp 0.1.0 (git+https://github.com/tomusdrw/parity-webapp.git)", ] @@ -693,6 +694,14 @@ name = "odds" version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "parity-status" +version = "0.1.1" +source = "git+https://github.com/tomusdrw/parity-status.git#31cdfd631af970b58c4ddb4e7d7e927af2e07ce3" +dependencies = [ + "parity-webapp 0.1.0 (git+https://github.com/tomusdrw/parity-webapp.git)", +] + [[package]] name = "parity-wallet" version = "0.1.0" diff --git a/webapp/Cargo.toml b/webapp/Cargo.toml index 377b0b556..b377bb991 100644 --- a/webapp/Cargo.toml +++ b/webapp/Cargo.toml @@ -17,6 +17,7 @@ ethcore-rpc = { path = "../rpc" } ethcore-util = { path = "../util" } parity-webapp = { git = "https://github.com/tomusdrw/parity-webapp.git" } # List of apps +parity-status = { git = "https://github.com/tomusdrw/parity-status.git" } parity-wallet = { git = "https://github.com/tomusdrw/parity-wallet.git", optional = true } clippy = { version = "0.0.61", optional = true} diff --git a/webapp/src/apps.rs b/webapp/src/apps.rs index 6a43decab..364186d04 100644 --- a/webapp/src/apps.rs +++ b/webapp/src/apps.rs @@ -17,21 +17,25 @@ use std::collections::HashMap; use page::{Page, PageHandler}; +extern crate parity_status; extern crate parity_wallet; pub type Pages = HashMap>; +pub fn main_page() -> Box { + Box::new(PageHandler { app: parity_status::App::default() }) +} + pub fn all_pages() -> Pages { let mut pages = Pages::new(); wallet_page(&mut pages); pages } -#[cfg(feature="parity-wallet")] +#[cfg(feature = "parity-wallet")] fn wallet_page(pages: &mut Pages) { pages.insert("wallet".to_owned(), Box::new(PageHandler { app: parity_wallet::App::default() })); } -#[cfg(not(feature="parity-wallet"))] +#[cfg(not(feature = "parity-wallet"))] fn wallet_page(_pages: &mut Pages) {} - diff --git a/webapp/src/lib.rs b/webapp/src/lib.rs index 104a8ce45..d8e524be8 100644 --- a/webapp/src/lib.rs +++ b/webapp/src/lib.rs @@ -60,7 +60,7 @@ impl WebappServer { let cors_domain = jsonrpc_http_server::AccessControlAllowOrigin::Null; let rpc = ServerHandler::new(handler, cors_domain); - let router = router::Router::new(rpc, apps::all_pages()); + let router = router::Router::new(rpc, apps::main_page(), apps::all_pages()); try!(hyper::Server::http(addr.as_ref() as &str)) .handle_threads(router, threads) diff --git a/webapp/src/router/mod.rs b/webapp/src/router/mod.rs index 4ed32fab9..fad8593b9 100644 --- a/webapp/src/router/mod.rs +++ b/webapp/src/router/mod.rs @@ -17,12 +17,14 @@ //! Router implementation use hyper; +use page::Page; use apps::Pages; use iron::request::Url; use jsonrpc_http_server::ServerHandler; pub struct Router { rpc: ServerHandler, + main_page: Box, pages: Pages, } @@ -33,15 +35,19 @@ impl hyper::server::Handler for Router { Some(ref url) if self.pages.contains_key(url) => { self.pages.get(url).unwrap().handle(req, res); } - _ => self.rpc.handle(req, res), + _ if req.method == hyper::method::Method::Post => { + self.rpc.handle(req, res) + }, + _ => self.main_page.handle(req, res), } } } impl Router { - pub fn new(rpc: ServerHandler, pages: Pages) -> Self { + pub fn new(rpc: ServerHandler, main_page: Box, pages: Pages) -> Self { Router { rpc: rpc, + main_page: main_page, pages: pages, } } @@ -75,13 +81,18 @@ impl Router { fn extract_request_path<'a, 'b>(mut req: hyper::server::Request<'a, 'b>) -> (Option, hyper::server::Request<'a, 'b>) { let url = Router::extract_url(&req); match url { - Some(url) => { + Some(ref url) if url.path.len() > 1 => { let part = url.path[0].clone(); let url = url.path[1..].join("/"); req.uri = hyper::uri::RequestUri::AbsolutePath(url); (Some(part), req) }, - None => { + Some(url) => { + let url = url.path.join("/"); + req.uri = hyper::uri::RequestUri::AbsolutePath(url); + (None, req) + }, + _ => { (None, req) } }