summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blog/mod.rs13
-rw-r--r--src/main.rs38
2 files changed, 51 insertions, 0 deletions
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<impl Reply, Rejection> {
+ Ok("test")
+ }
+
+ pub async fn post(name: String) -> Result<impl Reply, Rejection> {
+ 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::<u16>()?,
+ ))
+ .await;
+
+ Ok(())
+}