diff --git a/Cargo.lock b/Cargo.lock index 064310b..407cada 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2187,6 +2187,7 @@ dependencies = [ "comrak", "envy", "log 0.4.8", + "mime 0.3.16", "pretty_env_logger", "rand 0.7.3", "ructe", diff --git a/Cargo.toml b/Cargo.toml index d970e06..47d9dbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ comrak = "0.7" envy = "0.4" log = "0" pretty_env_logger = "0" +mime = "0.3.0" rand = "0" ructe = "0.11" serde_dhall = "0.5.3" diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs new file mode 100644 index 0000000..e018bd8 --- /dev/null +++ b/src/handlers/mod.rs @@ -0,0 +1,9 @@ +use crate::templates::{self, RenderRucte}; +use warp::{ + http::{Response, StatusCode}, + path, Filter, Rejection, Reply, +}; + +pub async fn index() -> Result { + Response::builder().html(|o| templates::index_html(o)) +} diff --git a/src/main.rs b/src/main.rs index d62e8e3..0ecdc5b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,8 @@ use anyhow::Result; -use warp::Filter; +use warp::{path, Filter}; pub mod app; +pub mod handlers; pub mod signalboost; const APPLICATION_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); @@ -15,9 +16,20 @@ async fn main() -> Result<()> { // GET /hello/warp => 200 OK with body "Hello, warp!" let hello = warp::path!("hello" / String).map(|name| format!("Hello, {}!", name)); - warp::serve(hello.with(warp::log(APPLICATION_NAME))) - .run(([127, 0, 0, 1], 3030)) - .await; + let files = warp::path("static") + .and(warp::fs::dir("./static")) + .or(warp::path("css").and(warp::fs::dir("./css"))); + + let site = warp::get() + .and(path::end()) + .and_then(handlers::index) + .or(hello) + .or(files) + .with(warp::log(APPLICATION_NAME)); + + warp::serve(site).run(([127, 0, 0, 1], 3030)).await; Ok(()) } + +include!(concat!(env!("OUT_DIR"), "/templates.rs")); diff --git a/templates/footer.rs.html b/templates/footer.rs.html index c1fb2ee..08b0a35 100644 --- a/templates/footer.rs.html +++ b/templates/footer.rs.html @@ -1,4 +1,5 @@ @() +