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/api/router.rs b/src/api/router.rs index 3fbef275..5416e9e9 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -3,7 +3,6 @@ mod auth; mod handler; mod request; mod response; -pub mod state; use std::str::FromStr; @@ -13,10 +12,11 @@ use axum::{ routing::{any, get, post}, }; use conduwuit::{Server, err}; +pub(super) use conduwuit_service::state::State; use http::{Uri, uri}; use self::handler::RouterExt; -pub(super) use self::{args::Args as Ruma, response::RumaResponse, state::State}; +pub(super) use self::{args::Args as Ruma, response::RumaResponse}; use crate::{client, server}; pub fn build(router: Router, server: &Server) -> Router { diff --git a/src/router/layers.rs b/src/router/layers.rs index 6920555d..70f3a660 100644 --- a/src/router/layers.rs +++ b/src/router/layers.rs @@ -6,8 +6,7 @@ use axum::{ }; use axum_client_ip::SecureClientIpSource; use conduwuit::{Result, Server, debug, error}; -use conduwuit_api::router::state::Guard; -use conduwuit_service::Services; +use conduwuit_service::{Services, state::Guard}; use http::{ HeaderValue, Method, StatusCode, header::{self, HeaderName}, 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/service/mod.rs b/src/service/mod.rs index eb15e5ec..3d7a3aa9 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -5,6 +5,7 @@ mod manager; mod migrations; mod service; pub mod services; +pub mod state; pub mod account_data; pub mod admin; diff --git a/src/api/router/state.rs b/src/service/state.rs similarity index 98% rename from src/api/router/state.rs rename to src/service/state.rs index 57eb94ca..c0884a5c 100644 --- a/src/api/router/state.rs +++ b/src/service/state.rs @@ -1,6 +1,6 @@ use std::{ops::Deref, sync::Arc}; -use conduwuit_service::Services; +use crate::Services; #[derive(Clone, Copy)] pub struct 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