From ef01d3badb9765271a5bf55a4f0702b68f099e2e Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Fri, 17 Dec 2021 19:57:03 -0500 Subject: Initial commit [WIP] Some routing exists. Still needs templating etc Signed-off-by: Cara Salter --- src/blog/mod.rs | 13 +++++++++++++ src/main.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/blog/mod.rs create mode 100644 src/main.rs (limited to 'src') diff --git a/src/blog/mod.rs b/src/blog/mod.rs new file mode 100644 index 0000000..199d6db --- /dev/null +++ b/src/blog/mod.rs @@ -0,0 +1,13 @@ +pub mod handlers { + +use warp::{Reply, Rejection}; +use warp::http::Response; + + pub async fn list() -> Result { + Ok("test") + } + + pub async fn post(name: String) -> Result { + Ok("Post test") + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..8e92b51 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,38 @@ +use color_eyre::eyre::Result; +use std::net::IpAddr; +use warp::Filter; + +use std::str::FromStr; + +pub mod blog; + +#[tokio::main] +async fn main() -> Result<()> { + color_eyre::install()?; + + // Load .env + kankyo::init(); + + let blog_base = warp::path!("blog" / ..); + let blog_list = blog_base.and_then(blog::handlers::list); + let blog_post = blog_base.and( + warp::path!(String) + .and(warp::get()).and_then(blog::handlers::post)); + + let blog = blog_list.or(blog_post); + + let site = blog.with(warp::log("site")); + + let server = warp::serve(site); + + server + .run(( + IpAddr::from_str(&std::env::var("HOST").unwrap_or("127.0.0.1".into()))?, + std::env::var("PORT") + .unwrap_or("3030".into()) + .parse::()?, + )) + .await; + + Ok(()) +} -- cgit v1.2.3