Browse Source

Initial commit [WIP]

Some routing exists. Still needs templating etc

Signed-off-by: Cara Salter <cara@devcara.com>
master
Cara Salter 5 months ago
commit
ef01d3badb
Signed by: muirrum
GPG Key ID: 90C66610C82B29CA
  1. 1
      .gitignore
  2. 1796
      Cargo.lock
  3. 17
      Cargo.toml
  4. 13
      src/blog/mod.rs
  5. 38
      src/main.rs

1
.gitignore vendored

@ -0,0 +1 @@ @@ -0,0 +1 @@
/target

1796
Cargo.lock generated

File diff suppressed because it is too large Load Diff

17
Cargo.toml

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
[package]
name = "site"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
warp = "0.3"
comrak = "0.12"
ructe = "0.13"
color-eyre = "0.5"
kankyo = "0.3"
[dependencies.tokio]
version = "1"
features = ["full"]

13
src/blog/mod.rs

@ -0,0 +1,13 @@ @@ -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")
}
}

38
src/main.rs

@ -0,0 +1,38 @@ @@ -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(())
}
Loading…
Cancel
Save