2024-05-09 15:59:08 -07:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2025-04-25 02:47:48 +01:00
|
|
|
use axum::{Router, response::IntoResponse};
|
2024-12-14 21:58:01 -05:00
|
|
|
use conduwuit::Error;
|
2025-05-01 18:46:30 +01:00
|
|
|
use conduwuit_service::{Services, state, state::Guard};
|
2024-07-15 01:49:30 +00:00
|
|
|
use http::{StatusCode, Uri};
|
2024-05-09 15:59:08 -07:00
|
|
|
use ruma::api::client::error::ErrorKind;
|
|
|
|
|
2024-07-30 01:25:07 +00:00
|
|
|
pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) {
|
|
|
|
let router = Router::<state::State>::new();
|
|
|
|
let (state, guard) = state::create(services.clone());
|
2024-12-14 21:58:01 -05:00
|
|
|
let router = conduwuit_api::router::build(router, &services.server)
|
2025-05-01 18:46:30 +01:00
|
|
|
.merge(conduwuit_web::build())
|
2024-06-05 07:30:30 +00:00
|
|
|
.fallback(not_found)
|
2024-07-30 01:25:07 +00:00
|
|
|
.with_state(state);
|
|
|
|
|
|
|
|
(router, guard)
|
2024-05-09 15:59:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
async fn not_found(_uri: Uri) -> impl IntoResponse {
|
2024-07-15 01:49:30 +00:00
|
|
|
Error::Request(ErrorKind::Unrecognized, "Not Found".into(), StatusCode::NOT_FOUND)
|
2024-05-09 15:59:08 -07:00
|
|
|
}
|