Skip to content

Commit

Permalink
Add frontend POC with htmx and tera
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanPlume committed Sep 3, 2024
1 parent 4415860 commit 746b2d6
Show file tree
Hide file tree
Showing 13 changed files with 349 additions and 5 deletions.
217 changes: 217 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions crates/services/web-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ chrono = { version = "0.4", default-features = false, features = [
"clock",
"serde",
] }
lazy_static = "1.4"
ormlite = "0.19"
secrecy = { version = "0.8", features = ["serde"] }
serde = { version = "1", features = ["derive"] }
serde-aux = "4"
tera = "1"
thiserror = "1.0"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
tower = "0.4"
tower-http = { version = "0.5", features = ["trace"] }
tower-http = { version = "0.5", features = ["fs", "trace"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
tracing-bunyan-formatter = "0.3"
Expand All @@ -34,7 +36,6 @@ tosurnament-core = { path = "../../libs/core" }
tosurnament-config = { path = "../../libs/config" }

[dev-dependencies]
lazy_static = "1.4"
once_cell = "1"
reqwest = { version = "0.11", features = ["json"] }
uuid = { version = "1", features = ["v4"] }
Expand Down
3 changes: 3 additions & 0 deletions crates/services/web-server/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub enum Error {
UnsupportedHeader,
#[error(transparent)]
DecodeError(#[from] DecodeError),
#[error(transparent)]
TeraError(#[from] tera::Error),
}

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -55,6 +57,7 @@ impl IntoResponse for Error {
Self::InvalidHeader(_) => ServerError::InvalidHeader,
Self::UnsupportedHeader => ServerError::InvalidHeader,
Self::DecodeError(error) => error.into_server_error(),
Self::TeraError(_) => ServerError::InternalServerError,
};
server_error.into_response()
}
Expand Down
14 changes: 14 additions & 0 deletions crates/services/web-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@ pub mod routes;
pub mod server_error;
pub mod startup;
pub mod telemetry;

use tera::Tera;

lazy_static::lazy_static! {
pub static ref TEMPLATES: Tera = {
match Tera::new("templates/**/*") {
Ok(t) => t,
Err(e) => {
println!("Parsing error(s): {}", e);
::std::process::exit(1);
}
}
};
}
7 changes: 7 additions & 0 deletions crates/services/web-server/src/routes/index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use axum::response::Html;

pub async fn index() -> crate::prelude::Result<Html<String>> {
Ok(Html(
crate::TEMPLATES.render("index.html", &tera::Context::new())?,
))
}
2 changes: 2 additions & 0 deletions crates/services/web-server/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod health_check;
mod index;
mod tournaments;

pub use health_check::*;
pub use index::*;
pub use tournaments::*;
Loading

0 comments on commit 746b2d6

Please sign in to comment.