From 4c8940569e5729213b7eee6f3d5be39b745b697b Mon Sep 17 00:00:00 2001 From: Melody Horn / boringcactus Date: Sat, 12 Jun 2021 23:24:33 -0600 Subject: actually implement the easy example --- src/contrib/admin/site/urls.rs | 8 ++++++-- src/http/mod.rs | 4 +--- src/lib.rs | 5 ++--- src/server/mod.rs | 11 +++++++++++ src/urls/mod.rs | 17 +++-------------- 5 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 src/server/mod.rs (limited to 'src') diff --git a/src/contrib/admin/site/urls.rs b/src/contrib/admin/site/urls.rs index 5e81c4e..ef23d55 100644 --- a/src/contrib/admin/site/urls.rs +++ b/src/contrib/admin/site/urls.rs @@ -1,3 +1,7 @@ -use crate::urls::Path; +use crate::http::{Filter, Reply}; +use crate::urls::{UrlMap, path}; -pub const URL_PATTERNS: &[Path] = &[]; +pub fn urls() -> UrlMap { + path::end().map(|| Reply::into_response("bruh")) + .boxed() +} diff --git a/src/http/mod.rs b/src/http/mod.rs index 69a0706..f8f1066 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -1,3 +1 @@ -pub struct Request {} - -pub struct Response(pub &'static str); +pub use warp::{Filter, Reply, reply::Response}; diff --git a/src/lib.rs b/src/lib.rs index 28e6ab9..b9cf73d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ pub mod contrib; pub mod http; +pub mod server; pub mod urls; -pub fn run_server(url_patterns: &[urls::Path]) { - todo!(); -} +pub use server::run_server; diff --git a/src/server/mod.rs b/src/server/mod.rs new file mode 100644 index 0000000..b275616 --- /dev/null +++ b/src/server/mod.rs @@ -0,0 +1,11 @@ +use crate::urls::UrlMap; + +pub fn run_server(filter_stack: UrlMap) { + let server_task = warp::serve(filter_stack).run(([127, 0, 0, 1], 3030)); + + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() + .block_on(server_task) +} diff --git a/src/urls/mod.rs b/src/urls/mod.rs index 1acf186..45720b6 100644 --- a/src/urls/mod.rs +++ b/src/urls/mod.rs @@ -1,16 +1,5 @@ -use crate::http::{Request, Response}; +pub use warp::path; -pub type View = fn(Request) -> Response; +use crate::http::Response; -pub enum Path { - View { - url: &'static str, - view: View, - name: &'static str, - }, - - Include { - url: &'static str, - content: &'static [Path], - }, -} +pub type UrlMap = warp::filters::BoxedFilter<(Response,)>; -- cgit v1.2.3