diff --git a/Cargo.lock b/Cargo.lock index 5f82384e..18375234 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1044,6 +1044,7 @@ dependencies = [ "askama", "axum", "conduwuit_build_metadata", + "conduwuit_service", "futures", "rand 0.8.5", "thiserror 2.0.12", diff --git a/src/router/router.rs b/src/router/router.rs index 2b9ce2ec..fdaf9126 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -2,8 +2,7 @@ use std::sync::Arc; use axum::{Router, response::IntoResponse}; use conduwuit::Error; -use conduwuit_api::router::{state, state::Guard}; -use conduwuit_service::Services; +use conduwuit_service::{Services, state, state::Guard}; use http::{StatusCode, Uri}; use ruma::api::client::error::ErrorKind; @@ -11,7 +10,7 @@ pub(crate) fn build(services: &Arc) -> (Router, Guard) { let router = Router::::new(); let (state, guard) = state::create(services.clone()); let router = conduwuit_api::router::build(router, &services.server) - .merge(conduwuit_web::build::().with_state(())) + .merge(conduwuit_web::build()) .fallback(not_found) .with_state(state); diff --git a/src/web/Cargo.toml b/src/web/Cargo.toml index 8e03a338..5c2dbebb 100644 --- a/src/web/Cargo.toml +++ b/src/web/Cargo.toml @@ -21,6 +21,7 @@ crate-type = [ [dependencies] conduwuit-build-metadata.workspace = true +conduwuit-service.workspace = true askama = "0.14.0" diff --git a/src/web/mod.rs b/src/web/mod.rs index 520a9a34..25ec868c 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -1,23 +1,34 @@ use askama::Template; use axum::{ Router, + extract::State, http::{StatusCode, header}, response::{Html, IntoResponse, Response}, routing::get, }; use conduwuit_build_metadata::{GIT_REMOTE_COMMIT_URL, GIT_REMOTE_WEB_URL, VERSION_EXTRA}; +use conduwuit_service::state; -pub fn build() -> Router<()> { Router::new().route("/", get(index_handler)) } +pub fn build() -> Router { + let router = Router::::new(); + router.route("/", get(index_handler)) +} -async fn index_handler() -> Result { +async fn index_handler( + State(services): State, +) -> Result { #[derive(Debug, Template)] #[template(path = "index.html.j2")] struct Tmpl<'a> { nonce: &'a str, + server_name: &'a str, } let nonce = rand::random::().to_string(); - let template = Tmpl { nonce: &nonce }; + let template = Tmpl { + nonce: &nonce, + server_name: services.config.server_name.as_str(), + }; Ok(( [(header::CONTENT_SECURITY_POLICY, format!("default-src 'none' 'nonce-{nonce}';"))], Html(template.render()?), diff --git a/src/web/templates/index.html.j2 b/src/web/templates/index.html.j2 index 51393822..648f5ddd 100644 --- a/src/web/templates/index.html.j2 +++ b/src/web/templates/index.html.j2 @@ -9,7 +9,7 @@
  • Read the documentation
  • Join the community
  • Log in with a client
  • -
  • Ensure federation works
  • +
  • Ensure federation works